Skip to content


Commit during dettached head

You commit your work and then you discovered that git head is dettached (typically because of commiting in git submodule).

git branch tempwork
git checkout master
git merge tempwork

Remove branches

  • Local branch: git branch -d the_local_branch
  • Remote branch: git push origin :the_remote_branch

Rename branches

  • Local branch: git branch -m <oldname> <newname>
  • Current local branch: git branch -m <newname>
  • Remove the remote: oldname and create the newname

Fixup commit

  • We have open merge request
  • Review with git log -p brings some necessary changes
  • Change the things
  • Do git commit as usual or …
  • Remember which commit brings the thing which should be changed
    git commit --fixup=COMMIT
    git rebase -i FIRST_NON_FIXUP_COMMIT_OR_PARENT --autosquash
    git push -f

Merge past commit together

git rebase -i THE_LATEST_COMMIT

Global configuration

File: ~/.gitconfig

    email = YOUREMAIL
    name = YOURNAME
    signingkey = YOURGPGKEY
    gpgsign = True
    gpgsign = True
    forceSignAnnotated = True
    default = current
    ui = true
    st = status
    ci = commint
    co = checkout
    br = branch
    ll = log --oneline --graph --all --decorate
    wdiff = diff --word-diff
    merge-all = !~/.developer/
    fix = "!git commit --fixup=HEAD"
    ri = "rebase -i --autosquash"

[diff "decrypt"]
    textconv = ansible-vault view
    excludesfile = ~/.gitignore
[includeIf "gitdir:~/Documents/work/"]
    path = ~/Documents/work/.gitconfig

Global gitignore


Delete tags

  • Local

    git push --delete origin TAGNAME
  • Remote

    git tag -d TAGNAME

Mirror to another git server

git remote add upstream git@ANOTHERGITSERVER:PATH
git fetch upstream
git push --force --tags --progress upstream HEAD:master

Remove submodule


  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule

Git watch

  • Install inotify-tools
  • Download your repository.
  • Copy file to your ~/.local/bin/gitwatch
  • Copy file gitwatch@.service to your ~/.config/systemd/user/gitwatch@.service
  • Change path in ExecStart to your actual home directory

    ExecStart=/home/bob/.local/bin/gitwatch $SCRIPT_ARGS
  • Initiate gitwatch for all required local repositories:

    systemctl --user --now enable gitwatch@$(systemd-escape "'-r' /home/bob/Documents/notes").service
  • Check the status of the service:

    systemctl --user status gitwatch@$(systemd-escape "'-r' /home/bob/Documents/notes").service