[git] Update a local branch with the changes from a tracked remote branch

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?

This question is related to git branch git-branch remote-branch

The answer is


You don't use the : syntax - pull always modifies the currently checked-out branch. Thus:

git pull origin my_remote_branch

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...

git pull

while you have my_local_branch checked out, and it will update from the tracked branch.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to branch

Get git branch name in Jenkins Pipeline/Jenkinsfile Why do I have to "git push --set-upstream origin <branch>"? Your configuration specifies to merge with the <branch name> from the remote, but no such ref was fetched.? When does Git refresh the list of remote branches? Fix GitLab error: "you are not allowed to push code to protected branches on this project"? Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository." Git: Merge a Remote branch locally git pull from master into the development branch Depend on a branch or tag using a git URL in a package.json? How can I copy the content of a branch to a new local branch?

Examples related to git-branch

How do I rename both a Git local and remote branch name? How do I create a master branch in a bare Git repository? git switch branch without discarding local changes Git: Merge a Remote branch locally Why call git branch --unset-upstream to fixup? Create a remote branch on GitHub How can I display the current branch and folder path in terminal? Git merge master into feature branch Delete branches in Bitbucket Creating a new empty branch for a new project

Examples related to remote-branch

When does Git refresh the list of remote branches? What are the differences between git remote prune, git prune, git fetch --prune, etc Git: Cannot see new remote branch Update a local branch with the changes from a tracked remote branch Git: which is the default configured remote for branch? How do I list all remote branches in Git 1.7+? How do I check out a remote Git branch? How do you remove an invalid remote branch reference from Git? Git checkout: updating paths is incompatible with switching branches How to clone all remote branches in Git?