Commonly Googled Git Commands

There are plenty of git cheatsheets on the web (Tower’s is my favorite), but many of them are lacking answers to the most common questions about workflow practices and dealing with mistakes. Here’s a list of some of the most commonly sought out answers to add to your personal cheatsheet.

Quick git add <all> options

Note: -A is the same as –all. -u is the same as –update.

 

Unstage files added with git add

 

Undo the last commit

 

Squash commits when merging a feature into the develop branch

 

Squash commits before merging using rebase

In the text editor that comes up, replace the words “pick” with “squash” next to the commits you want to squash into the commit before it. Save and close the editor, and git will combine the “squash”ed commits with the one before it. Git will then give you the opportunity to change your commit message. To change your commit, comment out every line except the one with your new message.

Important: If you’ve already pushed commits to GitHub, and then squash them locally, you will have to force the push to your branch using git push -f

Helpful hint: You can always edit your last commit message, before pushing, by using: git commit --amend

 

 

Fixing a mistaken rebase

 

 

Storing/moving uncommitted changes

Note: Alternatively to git stash apply , you can use git stash pop  which works identically except it also throws away the (topmost, by default) stash after applying it (whereas git stash apply leaves it in the stash list for possible later reuse). This happens unless there are conflicts after git stash pop, in this case it will not remove the stash, behaving exactly like git stash apply. Another way to look at it: git stash pop is git stash apply && git stash drop .

 

Pull a remote branch not in the local repository
In versions of git 1.7.2.3 and higher you can simply type:

You should then see a message like:

This is short for git checkout --track <remote>/<branch name>  which is short for git checkout -b <branch name> <remote>/<branch name> . You can read more here.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.