image

Git Cheat Sheet

1 Jan, 2022 Abdelrahman Etry

Common GIT Commands

simple GIT commands Cheat Sheet that will help you with GIT and will make you understand how and when should you use which command

 

  • Create an empty Git repository or reinitialize an existing one
 git init
  • Add files
git add <file_name>
  • Add modified and untracked files

git add.
  • Save your changes to the local repository

git commit -m 'commit message'
  • Modify the most recent commit

git commit --amend
  • Display the state of the working directory and the staging area
 git status
  • Display the state of the working directory and the staging area in short format
git status --short
  • Discard all changes and replace the version of the file you have in working directory with the one you have in staging area

git checkout -- <file_name>
  • Takes your uncommitted changes (both staged and unstaged), saves them away for later use

git stash
  • Shows the existing stash entries

git stash list
  • List the available tags in repository
git tag
git show
git tag -l ".*"
  • Revert the changes that you just made and go back to the files that you had
git reset HEAD <file_name>
  • Remove individual files or a collection of files

git rm <file_name>
  • Move files within a git repository without deleting its history

 git mv <source> <destination>
  • List commits made in repository in reverse chronological order

 git log
  • Create a new connection record to a remote repository
 git remote add [remote_name] [remote_URL]
  • List available repositories
git remote
  • Clone a remote repository to your local machine

git clone [repository_URL]
Example: git clone https://github.com/abdelrahman-etry/Laravel-Stripe.git
  • Fetch data from an origin

git fetch [remote-name]
Example:  git fetch origin
  • Upload local repository content to a remote repository

git push [remote-name] [branch-name]
Example : git push origin master
  • Tidy repository by deleting untracked files
 git clean -f -d