Useful config đź”—
- branch.autosetuprebase=always (documentation): I find it easier to work with Git this way
- core.editor=emacs -nw (documentation): that's the editor that will be invoked every time Git needs to ask you about a commit message, when you're squashing commits, etc (and of course, you want emacs for that)
- commit.gpgsign=true (documentation) and gpg.program=gpg2 (documentation): you will need to set up these variables (and possibly a couple other) if you want to sign your commits to GitHub using GPG (recommended)
Safest way to “update” a local copy 🔗
I find this sequence of commands the “safest” way to quickly “refresh” a clone of some remote repo, and at the same time check its status (where “safest” means “reducing to the minimum the probability of messing up things with conflicts, outdated branches, uncommitted changes, etc”):
- $ git branch -a displays information about all branches, both local and remote
- $ git pull -r fetches changes from the remote and “rebases the current branch on top of the upstream branch after fetching”
- $ git status shows you the status of your copy: whether there are new files, missing files, unstaged changes, or commits pending push
- $ git remote prune origin --dry tells you if any branch in the remote has been recently removed. (Submit the same command without the --dry part to actually remove those remotes from your local origin. That will still not remove local branches automatically, but you can do that yourself with git branch -d <BRANCH> if you see some branch is no longer necessary.)
You can have those four lines as an alias, or inside a script somewhere.
Even better: if you set up the aliases suggested above, the whole thing becomes:
You can then type it and run it just once, and, from that moment on, simply recover the line from your shell history.
For example, if you're using Bash: press Ctrl+r, then start typing a distinctive chunk of the line (eg, r;, or st;gi); if you used it not too long ago for the last time, the entire line should appear, and you can simply press Enter.
An alias to view the history of the repo đź”—
Then, simply type
for a colourful graph of commits, tags and branches.