A must-GIT cheat sheet for every developer.

A must-GIT cheat sheet for every developer.

A git cheat sheet is one of the go-to commands for all the developers. It not only saves developers important time but also makes us feel good to share our work among developer communities.

These are some very handy git commands which I am going to share and it's going to be very fruitful in our daily development life.

Often times we get stuck and can't remember the exact git command for the specific work so here u go with all these obsolete yet very essential cheat sheets.

Here you can download GIT for your machine and start working with it!


Cheat sheet starts here


  • git init creates new repo inside the current directory
git init
  • git status gives us the status of all the current files whether it has been added or not.
git status
  • git add . adds up all the files for the next commit.
git add .

in case we want to add only a specific file for the next commit use the below syntax.

  • git add fileName
git add fileName
  • git commit -m commit all local changes
git commit -m "my message goes here"

In case you are new to GIT and want to configure up your email & password follow the below commands.

  • git config --global user.name "yourName"

  • git config --global email.name "yourEmail.com"

git config --global user.name "yourName"
git config --global email.name "yourEmail.com"

Now you have committed all your changes and want to push your code to the git so before that follow below command in order to tell your local folder that where it need to push the code in the git.

  • git remote add origin URL
git remote add origin URL

NOTE: The URL we need to specify here is the new repo URL refer the below screenshot

git article.PNG

  • git push -u origin master pushes all our code base to the github repository.
git push -u origin master
  • UPDATE

Fetch latest changes from origin

 git fetch

Pull latest changes from origin

git pull
  • PUBLISH

    commit all local changes

git commit -a

commit all previously staged changes

git commit -m "descriptive message"

push changes to origin

git push [origin] [branch]

BRANCH

create a new branch

git branch branchName

checkout out to any branch

git checkout branchName

Delete a branch

git delete -d branchName

REVERT

Revert last commit

git revert HEAD  (create a new commit)

Revert specific commit

git revert $id (creates a new commit)

Fix the last commit

git commit -a --amend

HISTORY

History of changes

git log


That's all for today. Hope this cheat sheet helps you in your daily development activities. Though it does not cover all the commands certainly a good guide to begin with.

Thanks a lot for taking out your precious time to take a look hope it helps you!