Jarle Aase

Git Cheat-Sheet

bookmark 1 min read

The following are some receipts for doing unusual things with git. Not unusual for power users of course, but sufficiently unusual that the weirdness is not captured by my long term memory (which is good - I don't want git to appear more important to my brain than things that actually matters).


Merge a branch into the current branch without history. I some times use this for merging feature branches or refactor branches where the history is of little significance.

git merge --squash <branch>

Merge a branch with history, but associate the commits with it's original branch. (It gives a better visual understanding of the projects history if you examine the history in a graphical tool, like gitk).

git merge --no-ff <branch>


Push branch to a remote server (in this case origin). I often do this to have feature branches I work on safely backed up in case my PC gets lost, or to allow others to take a look at my code before I merge a feature in to the master branch.

git push -u origin <branch>


Pull from an unrelated repository. Typically, when I have a local git-repository with code in it, and want to push to a newly created public repository, for example on GitHub. I pull from the public repository, handles merge conflicts, and then push.

git pull --allow-unrelated-histories origin master


Update (and optionally init) submodules

git submodule update --remote --merge --recursive --init


Undo the most recent commit (for example to ad more changes or change the comment).

git reset --soft HEAD~