Git - Tips


(how to) undo git reset HEAD~ or git --commit amend

  1. http://stackoverflow.com/questions/2510276/undoing-git-reset
  2. https://stackoverflow.com/a/1459264/3632318
$ git reset 'HEAD@{1}'

or

$ git reset ORIG_HEAD

when git commit --amend is undone, hash of the last commit is restored to its original value -> changes can be safely pushed to remote repo without --force option.

(how to) fork a fork and sync it with original repo

  1. https://help.github.com/articles/syncing-a-fork/
  2. https://github.com/Esri/developer-support/wiki/Setting-the-upstream-for-a-fork
$ git clone <MY_FORK_REPO>
$ git remote -v
$ git remote add upstream <UPSTREAM_REPO>
$ git fetch upstream
$ git merge upstream/master
$ git mergetool

(how to) remove file from Git

  1. https://stackoverflow.com/a/1143800/3632318
$ git rm --cached config/database.yml

(how to) sign GitHub commits

glossary

  1. https://superuser.com/a/769488/326775

for example:

$ gpg --list-keys --keyid-format LONG
/Users/tap/.gnupg/pubring.gpg
-----------------------------
pub   rsa4096/ACFDF508F789A2CB 2017-10-17 [SC]
      D9CA996601640B2121F29312ACFDF508F789A2CB
...

official guides

  1. https://help.github.com/articles/generating-a-new-gpg-key/
  2. https://help.github.com/articles/associating-an-email-with-your-gpg-key/
  3. https://help.github.com/articles/signing-commits-using-gpg/

use gpg --full-generate-key command to generate keypair - not gpg --gen-key command: the latter uses default key size of 2048 bits which can’t be changed.

$ZDOTDIR/.zshenv

$ZDOTDIR/.zshrc

https://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html

gpg-agent is a daemon to manage secret (private) keys independently from any protocol.

The agent is automatically started on demand by gpg, gpgsm, gpgconf, or gpg-connect-agent. Thus there is no reason to start it manually.

=> it’s not necessary to start gpg-agent manually (either via gpg-agent command or corresponding plugin provided by your plugin manager for Zsh).

~/.gnupg/gpg.conf

  1. https://gist.github.com/bmhatfield/cc21ec0a3a2df963bffa3c1f884b676b

~/.gitconfig

(how to) use common configs in Git repo

just use hardlinks instead of symlinks - they are commited to Git repo like ordinary files.

UPDATE

still it’s not possible: at some point (most likely, when hardlinked file is changed in upstream) hardlink and original file no longer share the same inode so fetched changes are not reflected in original file.

(how to) show git diff output in pager

  1. https://superuser.com/questions/366930/how-do-i-get-the-git-pager-to-clean-up-screen-output-after-exit#comment2040311_1202694
  ; ~/.gitconfig

  [core]
    ; ...
+   pager = less -+X -+F

don’t use git-up gem

  1. https://github.com/aanand/git-up

https://github.com/aanand/git-up#warning

This project is no longer maintained, for several reasons:

  • As of Git 2.9, git pull –rebase –autostash does basically the same thing.

=> add Git alias instead:

set upstream

  1. Git - Notes

see the linked post for details on how and why it’s necessary to set upstream for your branch - git-up gem would handle it for us before but now we should do it by ourselves.

(how to) merge master into develop

$ git checkout develop
$ git merge master
$ git mergetool
$ git commit -m "merge master"
$ git push

NOTE: it’s important to create and push commit even if there are no changes when all conflicts are resolved (git status displays a message that working tree is clean).