3

There is remote branch: R

There is local branch: L (which was created based on R)

So the graph is

 R--R1---R2--- \ L--L1-- 

Right now, I just need keep L branch always have the updates from R

What is the simplest way I can do this?

I think the answer is to:

  1. pull updates from local R first
  2. checkout to L and merge

But this does not seem very straightforward and I need do some conflict handling manually.

2 Answers 2

2

You want to make L a tracking branch for R. You can do this with the command.

git branch --track L remote/R 

Then, any time you are on branch L, just run git pull remote and it will pull updates and automatically merge them into your repository.

https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches

Sign up to request clarification or add additional context in comments.

3 Comments

I don't think he want to L to track R. L is just a local branch that the OP uses for local development and that the OP wants to sync with the latest changes on R. If L would track R, then he could push directly from L to R, which might not be what the OP wants.
Thanks all you guys ! My intention is to keep local branch L relating to remote branch R, so "git branch --track L origin/R" should work , right ? (only difference is origin replace remote )
Yes. "remote" is the name of the remote repository. I don't deal with remote repos much, so my syntax might be slightly off. Please correct me if it is.
1

You can pull directly into L from R. Assuming L is checked out:

git pull origin R 

L doesn't have to be tracking branch for you to pull in remote changes.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.