git tags

Updated: 30 August 2024

Show tags

git tag

Add a tag to current commit

git tag tagname

Add an annotated tag to a specific commit

git tag -a tag_name commit_id -m "message"

Add tag to arbitrary commit

git tag tag-text the-ref

Push tag to remote

git push origin tagname

List tags with date (from Stackoverflow)

git for-each-ref --sort=creatordate --format '%(refname) %(creatordate)' refs/tags

Delete a tag

git tag -d foo-tag

git branch

Updated: 28 August 2024

Create a branch and switch to it at the same time

git checkout -b iss53

Delete a remote branch

git push origin --delete feature/login

Delete a remote tracking branch

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

Remove upstream info for the_branch.

git branch the_branch --unset-upstream

Delete a local branch

git branch -d branch-name

Rename a branch

git branch -m <old> <new>

List both remote-tracking branches and local branches

git branch -a

Move branch pointer to another arbitrary commit

git branch --force <branch> <commit>

Create new branch at arbitrary commit

git branch branch_name commit_hash

Push all branches to a remote

git push origin --all

git diff

Updated: 09 August 2024

Show the changes required to get from branch1 to branch2

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 a directory between branches

git diff master..mybranch path/to/dir

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 branch1 branch2

Diff two directories not tracked by Git

git diff --no-index Downloads Downloads-copy

Highlight changed words using only colors

git diff --color-words

Generate diffs with n lines of context instead of the usual three

git diff --unified=0
git diff -U0

Show only names of changed files

git diff --name-only master media-coverage

Diff two arbitrary files, not necessarily under git controld

git diff --no-index path/1/code.php path/2/code.php

diff algorithms

How different are Git algorithms?

In Git, there are four diff algorithms, namely Myers, Minimal, Patience, and Histogram. The Minimal and the Histogram algorithms are the improved versions of the Myers and the Patience respectively.

git diff --minimal foo bar
git diff --patience foo bar
git diff --histogram foo bar
git diff --anchored=<text> foo bar

git diff --diff-algorithm=myers foo bar
git diff --diff-algorithm=minimal foo bar
git diff --diff-algorithm=patience foo bar
git diff --diff-algorithm=histogram foo bar

git

Updated: 16 June 2024

Stop tracking a folder

git rm -r --cached path_to_dir/

In a tracked directory show the location of the .git folder

git rev-parse --show-toplevel

Auto commit and push

for run in {1..1000}; do git add . && git commit -m 'auto save'; git push bb-chris; sleep 45; done

List all files currently tracked in that_branch

git ls-tree -r that_branch --name-only