git config

Updated: 14 May 2024

Username and email

git config --global user.name "John Doe"
git config --global user.email "who@ever.cloud"

Colours

git config --global color.status.updated magenta
git config --global color.status.untracked magenta
git config --global color.diff.old magenta

Set vim as default editor

git config --global core.editor "vim"

Temporarily switch to another ssh private key

git --config "core.sshCommand=ssh -i /home/mruser/.ssh/id_rsa" fetch

git rebase

Updated: 24 May 2023

Rebase onto

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

If required to squash into the first commit of a repository

git rebase --interactive --root

git ignore

Updated: 26 August 2024

Git ignore uses globbing patterns.

Ignore .env file in current directory only and not .env files which might occur further down the directory structure

# .gitignore

/.env

Find which .gitignore entry is responsible for ignoring a particular file

git check-ignore --verbose file/to/check.cs

Show all files being ignored, recursively

find . -type f  | git check-ignore --verbose --stdin

git log

Updated: 26 March 2024

All the refs in refs/

git log --all

All the refs in refs/heads

git log --branches

All the refs in refs/remotes

git log --remotes

All the refs in refs/tags

git log --no-walk --tags

Draw a text-based graphical representation of the commit history

git log --graph --oneline --decorate --all

Refresh git log periodically (every second) with watch utility

watch --color -n 1 git log --graph --oneline --decorate --all --color=always

Show commit which added a file

git log --diff-filter=A -- dotnet.code-workspace

Shows commits that changed a single file, including those commits that occurred before the file was given its present name.

git log --follow builtin/rev-list.c

Find commits by a particular author

git log --author='Chris Taylor'

git remote

Updated: 18 August 2024

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 origin origin_bitbucket

Delete reference to a remote

git remote remove temp-remote

Add a remote

git remote add origin git@github.com:User/UserRepo.git

Ping a remote by listing it’s references

git ls-remote opt_remote_name

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