git show

Updated: 07 October 2024

List files which were touched by a commit

git show --pretty="" --name-only REVISION

Show a file at a particular revision

git show REVISION:path/to/the/file

git bare

Updated: 16 June 2024

Initialize a repo with no working directory e.g. a shared repository. Developers can clone shared-project.git

git init --bare shared-project.git

Use a bare git repo to control a working-tree in another directory

git --work-tree=path/to/my-code --git-dir=path/to/bare-repo.git <usual git commands>

git push

Updated: 30 May 2024

Push everything to a new remote

git push new-remote --all
git push new-remote --tags
# Also push remote branches to new-remote, even where local copies do not exist.
git push new-remote 'refs/remotes/origin/*:refs/heads/*'

git clone

Updated: 17 May 2024

Clone a single branch from a repository

git clone --branch xdebug2 https://github.com/xdebug/xdebug.org.git

git patch

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

git clean

Updated: 05 February 2024

Remove un-tracked directories (including empty directories) and files from the working tree

git clean -fd

git instaweb

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

git bisect

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

git checkout

Updated: 20 June 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(s), as it was at a particular commit

git checkout commit-hash -- my/file another/file2

git search

Updated: 06 July 2023

Search the text (case insensitive) of commit messages in all branches

git log --all -i --grep='text to find'