DevOpsOpen Source SoftwareTutorials

How to pull a specific remote branch with git

git

When running the git pull command, you retrieve the latest changes of your current branch from the remote repository.

To find out which branch you are currently working on, you can use git status:

ck@mint ~/Git/myrepo $ git status
On branch main
nothing to commit, working tree clean

Sometimes you want to pull the changes from another branch, which has not yet been downloaded to your local machine.

To do that, you can use git pull but with the wanted branch added to the command:

ck@mint ~/Git/myrepo $ git pull origin systemd-improvements
From ssh://git.example.com/group/myrepo
 * branch            systemd-improvements -> FETCH_HEAD
Updating 288c86e..0d0cfeb
Fast-forward
 myapp.spec                    | 29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

After pulling the additional branch "systemd-improvements" from the remote repository, you can now locally change to this branch and continue working on it:

ck@mint ~/Git/myrepo $ git checkout systemd-improvements
branch 'systemd-improvements' set up to track 'origin/systemd-improvements'.
Switched to a new branch 'systemd-improvements'
Claudio Kuenzler
Claudio has been writing way over 1000 articles on his own blog since 2008 already. He is fascinated by technology, especially Open Source Software. As a Senior Systems Engineer he has seen and solved a lot of problems - and writes about them.

You may also like

Leave a reply

Your email address will not be published. Required fields are marked *

More in:DevOps