Git Commands cheat sheet

Git is a command-line tool, the following commands are the most used:

Git configuration commands

  • git config is used to configure and set up Git for the first time:
 $ git config

 $ git config --global "your name"
 $ git config --global "your-email"
 $ git config --list

Create and initialize a Git Repository

 $ git init

 $ git status
 $ git add file_name.js

 $ git add file_name1.js  file_name2.txt  file_name3.js

 $ git add .

 $ git add --all

 $ git add -A

 $ git rm --cached file_name.js

 $ git reset file_name.js

Git commit commands

  • The command git commit is an important Git command. To use this command, you should have at least added one file to the staging area.
 $ git commit -m "Add your message here"

 $ git commit -a -m "Your message here"

 $ git reset --soft HEAD^

 $ git add file_name.html

 $ git commit --amend -m "Add your message here"

Git branch commands

Git branch commands are very helpful specially when you are working on a project with other developers.

 $ git branch

 $ git branch branch_name

 $ git checkout brunch_name

 $ git merge your_branch_name

 $ git branch -d branch_name 

Git Push and Pull commands

Git push and git pull are both Git remote commands.

 $ git push -u origin branch_name
 $ git push 
 $ git pull

Git help commands

 $  git help

 $  git help <theCommandName>

Git remote commands

 $ git remote add origin

 $  git remote -v

 $ git clone

 $ git clone  -branch  branch_name

 $ git remote add upstream

 $ git clone --bare

 $ git push --mirror

 $ rm -rf repository-name.git
Translate »