$ git checkout -b branch2īranch 'branch2' set up to track remote branch 'branch2' from 'origin'.
#SET UPSTREAM ORIGIN MASTER GIT CODE#
Let’s create a new branch and use our alias in order to push our code and create the upstream branch easily. Using a bash aliasĪlternatively, you can use a bash alias if you don’t want to modify your existing git commands.ĭefine a new bash alias using the “ alias” command and define a name for it. $ git pushdīranch 'branch' set up to track remote branch 'branch' from 'origin'. When you are done adding and committing fiels to your repository, set the upstream branch using your newly defined alias. In order to create a new git alias, use the “ git config” command and define a new alias named “pushd” $ git config -global alias.pushd "push -u origin HEAD" In order to avoid having to define the upstream everytime you create a new branch, define an alias for the command we just wrote.įor aliases, you have two choices, you can either create a git alias or a bash alias. In fact, pushing to HEAD is equivalent to pushing to a remote branch having the same name as your current branch. Set upstream branch using an aliasĪnother way to set the upstream branch is to define an alias for your “git push” command. We have successfully set the upstream branch for our newly created branch. * branch 808b598 Initial commit master 808b598 Initial commit Let’s have a look at the tracking branches again with the branch command. $ git push -u origin branchīranch 'branch' set up to track remote branch 'branch' from 'origin'. We can set the upstream branch using the “git push” command. Master 808b598 Initial commitĪs you can see, compared to master, the branch “branch” has no tracking branches yet (and no upstream branches as a consequence)
You can check tracking branches by running the “ git branch” command with the “ -vv” option. $ git push -set-upstream Īs an example, let’s say that you created a branch named “ branch” using the checkout command. $ git push -u Īlternatively, you can use the “ –set-upstream” option that is equivalent to the “-u” option. The easiest way to set the upstream branch is to use the “ git push” command with the “-u” option for upstream branch. Inspecting tracking branches configuration.Why are upstream branches so useful in Git?.
Set tracking branches for existing local branches.Set tracking branches for new local branches.Set upstream branch for an existing remote branch.In your case, you have made other modifications, perhaps mistakes. # Verificando a ligacao `master` -> `origin/master` Nothing to commit, working directory clean (use "git branch -unset-upstream" to fixup) Your branch is based on 'origin/master', but the upstream is gone. $ echo "txt" > file.txt & git add file.txt & git commit -m "Initial commit" # Criação do primeiro commit, necessario para ter um `git status` normal. Warning: You appear to have cloned an empty repository. Initialized empty Git repository in /tmp/remote.git/ $ mkdir remote.git & cd remote.git & git init -bare & cd. Example: # Criação d'um repository remoto When you create a remote repository ( git init -bare ), it has no branch but when you clone the remote into a local repository, the master branch has an upstream link to origin/master, even if origin/master does not yet exists. Git branch master -set-upstream-to=origin/master To summarize, -unset-upstream just deletes a link locally, without deleting any data. Also, git status will no longer show the divergence between yo remote local branch. The consequence of this is just that in a git fetch|pull|push, you will have to manually need the local branch yo remote branch parameters to make the connection. Answer:ġ/ Push to create the remote branch, then create the missing link: git push origin masterĢ/ Break the local link between master and origin/master : git branch -unset-upstream So I want to understand what this -unset-upstream and why it asks me for it. Why do I need to run this -unset-upstream ? What does this command mean? Did I do something wrong in the previous steps? Afterwards the branches end up working out, but I don't like to do things randomly. (use "git branch –unset-upstream" to fixup)"
"Your branch is based on 'origin/master', but the upstream is gone. Now I do a branch called test, and I do add/commit/push.Īnd now here's what I wanted to ask: when I go back to the master branch, the message comes up: Then I clone it locally, create the remote (remote), create a file teste.php and then add/commit/push. I created a project and let it hosted remotely.