Updated: 06 July 2023
Search the text (case insensitive) of commit messages in all branches
git log --all -i --grep='text to find'
Freelance software engineer United Kingdom
Updated: 06 July 2023
Search the text (case insensitive) of commit messages in all branches
git log --all -i --grep='text to find'
Updated: 08 May 2023
Fetch a GitHub pull-request to your local repo
git fetch origin pull/<pull request id>/head:<branch name to use>
Updated: 27 March 2023
git log --pretty=format:"%C(yellow)%h%Creset %Cblue%an%C(auto)%d%Creset %s %<(3,trunc)%C(cyan)%b" --graph --boundary commit-a..commit-b
%an
author name.%b
message body.%<(3,trunc)
truncate next placeholder, in this case message body.Updated: 01 February 2023
Show individual files in untracked directories
git status -u
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
Updated: 25 November 2022
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
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
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'
Updated: 02 December 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