Git Cheatsheet

Clone

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

Status

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

git rebase master

Leave a Reply

How to post code in comments?