Automating Git Branch Pushing
Hello! Welcome to the third part of the Learning Git and GitHub series. In this post we will be covering how to automate the process of pushing a new branch to GitHub.
This post will be using the same repository my-first-repository
that we created in the first post.
Why can this be helpful?
When working on a project, you may find yourself creating a lot of branches. This can be for a number of reasons, such as creating a new feature, fixing a bug, or even creating a new blog post. When you create a new branch, you will need to push it to GitHub so that it is available for others to see and collaborate on. This can be a repetitive process and can be automated using a few simple steps.
For example, when we create a branch and try and push we get the following message.
# git add * && git commit -m "manual git branch push" && git push
[feature/manual-git-pushing 9a03f42] manual git branch push
1 file changed, 1 insertion(+)
create mode 100644 git-push-file-one
fatal: The current branch feature/manual-git-pushing has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature/manual-git-pushing
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
As we can see here, we have to change the upstream branch to be able to push, and at times when your making multiple changes and branches, Well I forget and then wonder why my changes are not showing up on GitHub. 😅
So lets fix this!
Automating the process
Looking at the local git docs git push help
we can see that there are two options true
or false
Local Docs Path: file:///C:/Program%20Files/Git/mingw64/share/doc/git-doc/git-push.html
|
|
Once this is set to true
we can now create a new branch and push it to GitHub without having to set the upstream branch.
|
|
Hey! Don’t forget to add a file and commit your changes before pushing!
|
|
Finally, you can see your git global config by running the following command.
|
|
Summary
So there we have it, we have now automated the process of pushing a new branch to GitHub. This can be helpful when working on a project and creating multiple branches. - This has been something, I’ve been meaning to do for a while now, and I’m glad I finally got around to it. 😅