Git Tips
Enable Javascript to display Table of Contents.
Git Shallow Clones
Saving disk space and speeding up git-clone with shallow clones.
git clone --depth=1 --branch feature/hugo git@github.hugo OUTPUT_DIR
The shallow clone can be converted to a "full clone" by: git fetch --unshallow
Diff-Viewer with Position-Highlighting
When using git diff
or git show
the diff viewer shows only which
lines have changed, but does not highlight the position of the change within the line. This
is better with the diff-so-fancy viewer. It can be installed like this:
$ sudo snap install diff-so-fancy
$ git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
If you want to return to the original diff viewer, perform these commands:
$ git config --global --unset core.pager
$ sudo snap remove diff-so-fancy
When redirecting the output to a file, the content will be in patch format.
Diff-Viewer with Side-by-Side
$ cargo install --locked difftastic
$ export PATH="$PATH:$(pwd)/.cargo/bin"
$ GIT_EXTERNAL_DIFF=difft git diff
Source: wilfred.me.uk
Git Aliases
Showing graph (list graph = lg) on command line:
git config --global alias.lg \
"log --graph --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ar)%Creset'"
Cleaning Repository
Removing all changes and untracked files:
$ git checkout .
$ git clean -fd
Mirroring a Repository
$ git clone --bare git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
Cloning into bare repository 'linux-stable.git'...
remote: Counting objects: 7958050, done.
remote: Compressing objects: 100% (142578/142578), done.
remote: Total 7958050 (delta 826748), reused 970167 (delta 826088)
Receiving objects: 100% (7958050/7958050), 1.43 GiB | 19.90 MiB/s, done.
Resolving deltas: 100% (6706483/6706483), done.
$ cd linux-stable.git/
$ git push --mirror git@intranet.lan.work-microwave.de:satcom/linux-stable-mirror.git
Enumerating objects: 7958050, done.
Counting objects: 100% (7958050/7958050), done.
Delta compression using up to 8 threads
Compressing objects: 100% (1202450/1202450), done.
...
$
Source: github.com