Thoughts and comments by John Sumsion about life and software.Alma 34:38 Live in thanksgiving daily, for the many mercies and blessings which he doth bestow upon you.

26 August 2015

Git worktree - clone but not quite

Have you ever wanted another workarea for the current repository you're working in? Maybe you're running some tests and need the normal workarea to stay unchanged, so you can't rebase or tweak another branch in the meantime.

This creates a new workarea in ../temp with all the current branches. It's the same repository! Any git command you do in the new workarea is applied to (and uses the database of) the original repository: commit, rebase, push, etc.

NOTE: If you leave off the branch name, 'git worktree add' creates a branch named after the new worktree directory.

NOTE: If you want to operate on the same branch as the original repository, it is disallowed by default. In order to operate on the same branch, you have to say $ git worktree add ../temp master -f'. Also if you ever move off of the branch and want to switch back when another worktree has the same branch checked out, you have to use an annoyingly-long option: $ git checkout master --ignore-other-worktrees. You could put that in an alias like so: $ git config --global alias.co "checkout --ignore-other-worktrees".

My Blog List

Disclosure: I am employed by FamilySearch. The views expressed here are the opinions of John Sumsion and do not necessarily reflect the views of FamilySearch or The Church of Jesus Christ of Latter-day Saints.