Git pull, merge changes is worktrees?

后端 未结 1 519
旧时难觅i
旧时难觅i 2021-01-14 14:50

I clone a repository from GitHub and I create a few worktrees with:

git worktree add -path- -branch-

W

相关标签:
1条回答
  • 2021-01-14 15:03

    Depending on what commands you use to "pull changes", the answer is either "no' or "not exactly".

    The simplest way to get updates from the remote is git fetch. This updates the database (by adding objects from the remote if they weren't already in the local repo) and may update refs. (Usually it updates remote tracking refs specific to that remote. It can be told to directly update local branches, but this is rarely a good idea.) In any event, fetch does not perform merges; either it leaves the local branches alone, or it updates them to match the remote and clobbers any local changes. (Again, the default is to leave them alone.)

    Having fetched, you could then cd into the worktree where you have a given local branch checked out and merge the corresponding remote tracking ref into that branch (or do a rebase that has a similar approach).

    git pull is a shorthand for doing a fetch followed by a merge. (Well... again, that's the default. You can change the configuration so that it becomes "fetch and then do a rebase"...) So if you're in a worktree where you have a given branch checked out, you can do a git pull and that could initiate a merge into that branch (using that worktree and its staging area).

    But if you're looking for a single command that would initiate merges into all of the worktrees (which is kind of what it sounds like you're asking), you would have to probably script something like that. (And honestly, I don't recommend such a thing.)

    0 讨论(0)
提交回复
热议问题