I have a local branch named 'my_local_branch
', which tracks a remote branch origin/my_remote_branch
.
Now, the remote branch has been updated, and I am on the 'my_local_branch
' and want to pull in those changes. Should I just do:
git pull origin my_remote_branch:my_local_branch
Is this the correct way?
You don't use the
:
syntax -pull
always modifies the currently checked-out branch. Thus:while you have
my_local_branch
checked out will do what you want.Since you already have the tracking branch set, you don't even need to specify - you could just do...
while you have
my_local_branch
checked out, and it will update from the tracked branch.You have set the upstream of that branch
(see:
--set-upstream-to
all the time?")
(
git branch -f --track
won't work if the branch is checked out: use the second commandgit branch --set-upstream
instead, or you would get "fatal: Cannot force update the current branch.
")That means your branch is already configured with:
Git already has all the necessary information.
In that case:
is enough.
If you hadn't establish that upstream branch relationship when it came to push your '
my_local_branch
', then a simplegit push -u origin my_local_branch:my_remote_branch
would have been enough to push and set the upstream branch.After that, for the subsequent pulls/pushes,
git pull
orgit push
would, again, have been enough.