To download the latest version of the GitHub server repository, the “git pull” command can be used. For performing this operation, they are required to set the desired local branch as a remote tracking branch. After that, they can perform multiple operations, such as “git fetch”, “git pull”, and “git push” commands. Moreover, developers are permitted to download the newly added changes of the remote repository into any local branch without navigating to it.
This blog will talk about the way of performing a “git pull” into a desired branch rather than the current without switching into it.
How to ‘git pull’ into a Particular Branch that is not the Current One?
To perform the “git pull” operation on the required local branch without switching into it, first, move to the desired branch. Next, view the all existing branches including remote and local. Select one of them which needs to download the updated version of the centralized server repository. Next, list the remote URL and execute the “git pull <remote-name> <branch-name:branch-name>” command.
Step 1: Navigate to Desired Repository
First, move to the particular repository by typing out the “cd” command:
Step 2: List All Branches
Then, execute the “git branch” command to view the list of all including remote as well as local branches:
Here, the “-a” option denotes all. As you can see, all branches are shown in the below-given output, and we have highlighted our target “beta” branch in which we want to download remote content:
Step 3: View Remote URL
Next, check the list of the available remote URL by running the “git remote” command:
Step 4: Pull To Particular Branch
Finally, execute the “git pull” command to download the latest version of the remote repository to the desired branch:
As you can see, we have successfully pulled the remote repository into the “beta” branch without switching into it:
That’s all! We have explained the process of “git pull” in a particular branch without switching to it.
Conclusion
To perform the “git pull” operation on the desired local branch other than the current, first, redirect the particular branch. Then, list the remote and local branches. Choose one of them in which you want to get the new version of the particular remote repository. Next, view the remote URL list and execute the “git pull <remote-name> <branch-name:branch-name>” command. This blog illustrated the way of performing a “git pull” into a desired branch rather than the current without switching into it.