Git notes and tips

GUI tools

Possibly the best GUI tool for git AND Mercurial is SmartGit: http://www.syntevo.com/smartgit/

It works on FreeBSD too.

Git strategy

We prefer to work on “master” branch (ie, “trunk”) and have long-lived branches.

We do not like the merge metaphor, but rather we use rebase, or cherry pick.

See: https://barro.github.io/2016/02/a-succesful-git-branching-model-considered-harmful/

Also: http://paulhammant.com/2013/04/05/what-is-trunk-based-development/

Import specific files from another branch, without merging (no history)

We can simply give git checkout the name of the feature branch [1] and the paths to the specific files that we want to add to our master branch.

git checkout source_branch <paths>…

If the branch and path have same name, then divide them with –

git checkout source_branch – <path>

Example: Import all the latest code from branch 01-poetry-vol1 into trunk (called master in git):

git checkout 01-poetry-vol1 – 01-poetry-vol1

Rebase a branch on top of another

For example, we want to import all commit from branch 01 into master, while keeping some, or all commits:

# We are in branch 01, and we switch to master
git checkout master

# We bring over all the commits from branch 01 on top of master
git rebase 01

# Then, we edit all commits: we can reject, merge, rename, reword, etc
git rebase -i

Git Extra

List of commands: https://github.com/tj/git-extras/blob/master/Commands.md

These are bash scripts that can be installed either with a package manager, or from source.

Some of the git-extra tools are very useful, since they offer complex git actions with a simple cli interface.