This guide provided the method of pushing a single Git branch to the GitHub server.
How to Push Only One Git Branch (and no Other Branches)?
In order to push a single Git branch to the GitHub server, follow the provided instructions:
- Redirect to the required Git directory.
- Check the list of all branches.
- Choose the target branch and switch to it.
- Ensure the remote URL list.
- Pull the latest version of the specific remote branch.
- Execute the “git push –force <remote-name> <target-branch-name>” command.
Step 1: Switch to Git Repository
Redirect to the particular Git repository by executing the “cd” command along with its path:
Step 2: Check Local and Fetched Remote Branches
Then, run the “git branch” command to display the fetched remote and existing local branches
Here, the “-a” option represents the all. Now, all the existing branches are displayed. We have selected the below-highlighted “alpha” branch, which needs to push to the GitHub server:
Step 3: Switch to Target Branch
Next, execute the “git checkout” command and navigate to the previously selected local branch:
Step 4: Verify Backend Connection Between Local and Remote Repositories
To ensure the GitHub server and local machine are connected with each other, use the provided command:
Step 5: Pull Remote Branch
After that, execute the “git pull” command along with the remote name and specify the branch to pull the content of the particular branch:
Step 6: Push Single Branch
Finally, utilize the “git push” command for updating the GitHub server with the local changes:
Here:
- “–force” option is used for pushing the local branch content forcefully.
- “origin” is the name of the remote URL.
- “alpha” is a particular branch that needs to be pushed.
As you can see, we have successfully pushed the content of the single file to the GitHub remote repository:
That’s it! We have explained the easiest way of pushing a single Git branch to the GitHub server.
Conclusion
To push a single Git branch to the GitHub server, first, redirect to the required Git directory. Then, check the list of all branches and select one of them. Next, switch to it and check the remote URL list. After that, pull the updated content of the specified remote branch. Lastly, execute the “git push –force <remote-name> <target-branch-name>” command. This guide demonstrated the procedure of pushing a single Git branch to the GitHub server.