Page 1 of 1

git worktree

Posted: Sun Oct 30, 2016 5:50 am
by JJRcop
Have two+ working trees that both hook into the same repo!

So I just now found this out but git since 2.5 (july 2015 :sad:) has a command that allows you to just make a new working tree and that tree will be linked to the master repo you used the command in.

(From root of current working tree)

Code: Select all

git worktree add ../tgstation2
This will checkout whatever branch you currently have checked out (by creating a new one based off it) into ../tgstation2 and now you can work on two branches at the same time instead of having to git stash or git commit your changes then reapply them back into the working tree. You can of course do this as many times as you want (providing different directory names silly), and it allows you to work on two or more branches literally at the same time with two dreammaker instances etc, and two versions of the game you can compile and use independently etc etc.

And also it's all linked to the same repo with the same refs (except HEAD and a few others i think). The commands you call are not being called on a cloned repo that is synced with the main repo, but the main repo itself, no hacky workaround methods used.

More info here: https://git-scm.com/docs/git-worktree


I really am very happy I found this and wish I found it way earlier.

Re: git worktree

Posted: Sun Nov 13, 2016 12:51 pm
by kevinz000
I'm a GUIscrub, does this work with git for windows?

Re: git worktree

Posted: Thu Nov 17, 2016 8:24 am
by JJRcop
kevinz000 wrote:I'm a GUIscrub, does this work with git for windows?
If you're talking about the GUI part of git for windows, then no, git-gui does not provide an interface to git worktrees. You must click "repository" at the top left and then click "Git Bash" to pop open a command line so you can use this feature.