git Git GIT

2019/08/01 (Edit 2019/08/27)
git, tip, command-line
Some tip for hacking Git.

Here's some tip for hacking Git: a powerful tool to manage text across some time within a team

understand what git is about, if not, read the official doc:

The commit

The branch

The rebase

The conflict

use git fetch, ditch git pull

git pull is a failed combo command, usually it'll cost you current un-committed change, and result in a hard reset.

so to skip the hassle, just git fetch to get the future, then git reset --hard @{upstream} when you're clear to get the change

use rebase, ditch merge (except for pull-request)

consider this when working with long branches (16+ commit).

merge cause messy history, and not able to do rebase is also a sign of bad git commit habit

focus the change, sort the commit, and use rebase

master cherry-pick, learn interactive rebase

if you do cherry-pick enough times, you got rebase if you change commit content during multiple cherry-pick, you got interactive rebase

moving commit can clean up the repo history

reordering & regrouping commits gives high quality history

if there's some later use for the commit history, and the quality of commit message matters, do both regularly

decide what commit strategy to use

know your .git/config, limit your global git config