Git Version: 2.5.1.windows.1 (via git-scm.com)
Setup:
Main Repo: Branch_A -> commit -> commit -> commit -> commit
\
Worktree: -> Branch_B -> commit -> commit
\
-> local Branch_C -> commit
I created a second work-tree via
git worktree add /C/repos/testbranch Branch_B
which worked fine
Now what I want to do is switch the worktree's branch back to branch Branch_B from outside after creating local branches (like Branch_C) in the worktree and commiting to them. Following this I've tried the following:
Checked out branch is Branch_C with one additional commit over Branch_B
git --work-tree=/C/repos/testbranch/ --git-dir=/C/repos/testrepo/.git/ checkout Branch_B
But the output I get is:
error: Your local changes to the following files would be overwritten by checkout:
bla <-- My test file which is COMMITTED and UNCHANGED in Branch_C
Please, commit your changes or stash them before you can switch branches.
Aborting
I tried doing this from different directories, tried adding/omitting --git-dir and some other things - nothing seems to work. What am I doing wrong?
Edit: Checking out the branch via
git checkout Branch_B
while in /C/repos/testbranch/ works fine.
Background: The repo I'm using is cloned from an SVN repo. What I'm trying to achieve is automating the process of "svn rebase"ing with ANT (<exec> task). The first step is to checkout the branch that points to a branch on the SVN repository. Unfortunately, just using checkout
in the ANT task fails with not a git repository: $SECOND_WORKTREE_DIR
.
Steps:
Found a solution.
You can circumvent the problem described above by executing the sh.exe installed with git and passing it a command (which can also be a cd
):
<exec executable="C:/Program Files/Git/bin/sh.exe" failonerror="true">
<arg value="--login"/>
<arg value="-c"/>
<arg value=""cd /C/repos/testbranch && git checkout Branch_B""/>
</exec>