Updated: 15 February 2024
Make a patch file from the 1st commit in HEAD
git diff @~1 @ > my.patch
Apply the patch file to another repo
git apply my.patch
Guernsey & Jersey, Channel Islands, UK.
Updated: 15 February 2024
Make a patch file from the 1st commit in HEAD
git diff @~1 @ > my.patch
Apply the patch file to another repo
git apply my.patch
Updated: 05 February 2024
Remove un-tracked directories (including empty directories) and files from the working tree
git clean -fd
Updated: 22 October 2023
Instantly browse your working repository in gitweb. A simple script to set up gitweb and a web server for browsing the local repository.
By default, instaweb will look for the lighttpd web-server, see https://christaylordeveloper.co.uk/web-server/lighttpd.
You will need to install gitweb first
sudo apt install gitweb
Run the instaweb script
git instaweb --start
Browse to http://127.0.0.1:1234/
Stop instaweb
git instaweb --stop
Updated: 27 August 2023
Start a bisect session
git bisect start
Pass git a commit where the problem is apparent
git bisect bad HEAD
and a good commit, sometime earlier
git bisect good fcd61994
Inspect / test the code, then inform git
git bisect good # or
git bisect bad
Finish the session
git bisect reset
Updated: 22 February 2024
Checkout a single file from a specific commit
git checkout <COMMIT> path/to/the/file
Checkout one file from another branch
git checkout grab-from-this-branch -- logout.js
Checkout file, as it was, at a particular commit
git checkout commit-hash -- my/file another/file2
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: 23 March 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"