Git Cheatsheet


git clone <path or url to repo>

Create an empty repo

git init

Check if upstream has updates

git fetch

Switch to another branch

git checkout mybranch

Pull upstream updates

git pull

Add a file

git add filename

Move a file

git mv sourcefile destinationfile

Note: You can move a directory or source file or destination file can include directories.

Delete a local branch

git branch -d mybranch


git status

Revert uncommitted changes to a file

git checkout path\to\file.ext

Remove all untracked files

This makes the repository clean again.
Do a dry run first with -n.

git clean -n

Then do it for real with -f.

git clean -fxd

git diff

git diff

git merge

git merge myBranch

Take all upstream source files

git checkout --ours .
git add .

Keep all local files

git checkout --theirs .
git add .

Abort the merge

git merge --abort

git rebase

This at first looks easy. But there is complexities, especially if you have already pushed.

git rebase master

If a merge conflict occurs, fix it and then run:

git rebase --continue

If you have already pushed, run this to push once rebase is complete.

git push --force-with-lease

Leave a Reply

How to post code in comments?