Back to Blog
Git add remote upstream5/25/2023 ![]() When creating a new local branch that should track the remote branch.When creating a new remote branch by pushing our local branch.We discussed three different cases in which we may need to set Upstream Branches: Setting Upstream Branches also helps us in comparing how far ahead or behind our local branch is when compared to the remote branch. We directly push and pull from the remote branches without worrying about the names of the remotes or the branches. Upstream Branches are extremely helpful for collaborative purposes. This implies that the remote master branch is the upstream branch for our local master branch. In the following output we can see that our local master branch tracks the remote-tracking branch origin/master. We can check the remote-tracking branches for a tracking branch by using the following Git Branch Command. Make sure you are currently on the local branch that you want to set an Upstream for. ![]() This can be done by using the Git Branch command. In this case, both the remote branch and the local branch exist and we want to set the remote branch as the Upstream for our local branch. We can set an Upstream Branch for an already existing local branch. $ git checkout -track Setting Upstream for an existing Local Branch We use the Git Checkout command with the -track option for doing this. To do this we have to create a new branch that is based on the remote-tracking branch. In this case, the remote repository already has a branch and we want to create a new local tracking branch that has this remote branch as an Upstream Branch. We can also set Upstream Branch for a new branch that we want to create. ![]() $ git push -set-upstream When creating a new Local Branch Before executing the following command make sure that you are on the branch that you want to push and set an Upstream for. It will not only push and create a new branch in the remote repository but also set it as an Upstream Branch. We can do this by using the -set-upstream or the -u flag along with the Git Push command. Setting an Upstream branch for this local branch will also prove to be helpful. There may be cases when we have a local branch that we want to push to a remote repository. There are many cases in which we may need to set Upstream Branches. Git shows information like the number of commits that we are ahead or behind from the remote branch.
0 Comments
Read More
Leave a Reply. |