This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 1-800-GIT-HELP
On Mon, Jan 13, 2020 at 10:29 AM Nathan Sidwell <nathan@acm.org> wrote:
> On 1/13/20 6:33 AM, Jonathan Wakely wrote:
> > I imagine a lot of people are going to feel lost in the first few
> > weeks of using Git.
>
> thanks. I have a question, but first some info that may well be useful
> to others.
>
> Today I learnt that one can use worktrees to work with different checked
> out branches, but sharing a local repo.
>
> In your checked out original clone do
> git worktree add ../some-other-dir branch-to-checkout
> then ../some-other-dir contains a checked out branch, tracking the
> upstream branch you named.
>
> Jonathan tells me that if you 'git fetch' from any of those checkouts,
> the underlying local repo gets updated, and you can git merge them as
> you desire.
>
Yes, this is very useful.
> Notice this example doesn't show /all/ the exiting things worktree add
> can do -- like renaming branches. That just confuses a newbie like me.
> Hackers, remember you learned about cardinals (and just called them
> numbers) before you discovered zero, and negative integers.
>
> Onto my question. I'm used to having a bunch of sibling directories,
> called trunk, pr12345, pr84241, feature-x, all with checked out trunks.
> I can't do that with worktrees, because:
>
> > git worktree add ../../using-enum/src master
> fatal: 'master' is already checked out at '/data/users/nathans/trunk/src'
>
Right. You don't want multiple worktrees to track the same branch; if you
change the branch in one, the other one becomes inconsistent.
> If I drop 'master' from the command I get:
> >git worktree add ../../error/src
> Preparing ../../error/src (identifier src1)
>
> * what does 'identifier src1' mean, and what did that do?
>
It created a branch src1 based on your current HEAD for the new worktree to
track.
* should I be using user branches for this?
>
> * is it possible do that all in one command?
> > git COMMAND ../../error/src SOMETHING
> ... now ../../error/src has a checked out /users/nathan/error branch
> created from master?
>
git worktree add -b error ../../error/src master
Jason