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.