
Otherwise, we’ll use the name of the current branch: local upstreamĪll that remains is to run the git command. If we’re passed a parameter, we’ll use that for the name of the upstream branch. We’ll set the result to a local variable called “current”: local currentĬurrent="$(git rev-parse -abbrev-ref HEAD)" I was going to name this function “gsu” but I have that aliased to git submodule update.įor this function, we must retrieve the name of the current branch. If you haven’t deciphered it yet, “gsut” stands for Git Set Upstream To.
We’re going to create a zsh shell function that will allow you to type: What if I gave you a better way? Enter Shell Functions. Let us say you have local branch named dev and want to create upstream branch origin/dev, then here is the command to do it.
git push -set-upstreamYou can also use set-upstream option to set upstream branch. So what do you do? You go to the mouse, swipe over the command to select it, copy it (if your terminal doesn’t do that automatically), paste it as a new command, fiddle with it a bit for accuracy, and press Enter. Here is the syntax to create upstream branch with git push. The command also allows you to change the default remote branch. Using the git set upstream command, you can choose the flow direction of your current local branch. Git branch -set-upstream-to=origin/ master Sending something upstream in Git means that you are sending it back to the repository owner. If you wish to set tracking information for this branch you can do so with:

Please specify which branch you want to rebase against. You’ve seen it many times: There is no tracking information for the current branch. So, in practice, you probably won't have to use -set-upstream-to very often.Update : I just learned about the new git setting: toSetupRemote - I learned it from here, and so can you! Note that if you create or checkout master locally, Git typically would create origin/master as the default tracking branch behind the scenes. So, keeping in mind that origin/master is the actual branch which tracks the true remote master branch, we can tell Git to use origin/master as the tracking branch via: # from local master branch Origin/master | local tracking branch for master which mirrors the remote version Origin master | the master branch on the remote (as in the git pull command) Here is a brief summary: master | the master branch (either local or remote) Then, it does a merge into your local master branch using origin/master. The first step, git fetch origin, updates the local tracking branch origin/master with the latest changes, such that it mirrors the true master branch on the remote. The first step, git fetch origin, updates the local tracking branch origin/master with the latest changes, such that it mirrors the true master branch on the remote. git fetch origin git merge origin/master. Whenever you sync with the remote master branch, locally you are actually using origin/master.ĭoing git pull origin master is actually identical to this (assuming you are using the merge strategy by default): git fetch origin It exists mainly to serve as a proxy for the true remote master branch.
It fetches and merges changes from the remote server to your working directory. git branch -set-upstream-to
Set upstream branch using the git push command with the -u extension or use the longer version -set-upstream. Switch to it using the checkout command with the -b. This is a local branch, which exists on your local repo. git push -u origin master git push -set-upstream origin master. Method 1: Set Upstream Branch Using Git Push 1. Now, for the confusion, there is a third branch called origin/master.

Similarly, there is also a branch called master which exists on the remote. The local branch master, which exists only in your local Git repo, is in what you do most of your actual development work. And you should have confusion, because it's confusing. You seem to have some confusion about references in the basic Git commands.
