git

Diff

Diff between branches

git diff branch1..branch2

which is equivalent to

git diff branch1 branch2

Diff of one file path

git diff branch1..branch2 -- myfile.cs

Diff of one file between version in given commit and local HEAD

git diff 2f43f286 index.php

Show the number of lines changed

git diff --stat
git diff --numstat

Diff from a common ancestor

git diff [options] commitA...commitB [--] [path...]

This form is to view the changes on the branch containing and up to commitB, starting at a common ancestor of both commit.

git diff A...B

is equivalent to

git diff $(git merge-base A B) B

Use separate tool (e.g. Meld) to view diff

git difftool --dir-diff

Rebase

Rebase onto

git rebase --onto newbase from-commit-after branch-to-move

Branches

Create a branch and switch to it at the same time

git checkout -b iss53

Delete a remote branch

git push -d remote-name branch-name

Delete a local branch

git branch -d branch-name

Delete a remote tracking branch

git branch -d -r remote-name/branch-name

Rename a branch

git branch -m <old> <new>

Remotes

Change url of remote

git remote set-url origin new-url

Fetch one branch from a remote

git fetch <remote_name> <branch_name>

Rename remote

git remote rename from to

Tags

Show tags

git tag

Add a tag

git tag tagname

Push tag to remote

git push origin tagname

Logging

git log --pretty=oneline
git log --graph --oneline --decorate --all

Misc.

Stop tracking a folder

git rm -r --cached path_to_dir/