You have 2 options:
1/ Push to create the remote branch, then create the missing link:
git push origin master
2/ Breaks the local connection between master
and origin/master
:
git branch --unset-upstream
The consequence of this is only that in a git fetch|pull|push
, you will need to manually specify the local branch and the remote branch parameters to make the connection. Also, git status
will no longer show the divergence between the local branch and the remote.
To summarize, --unset-upstream
only deletes a connection locally, without deleting any data. You can then and at any time redo the connection:
git branch master --set-upstream-to=origin/master
Generally
When you create a remote Repospository (git init --bare
), it has no branch but when you clone the remote in a local Repository, branch master
has a connection (upstream) with origin/master
, even if origin/master
does not exist yet. Example:
# Criação d'um repository remoto
$ mkdir remote.git && cd remote.git && git init --bare && cd ..
Initialized empty Git repository in /tmp/remote.git/
# Criação de um clone locale
$ git clone remote.git local && cd local
Cloning into 'local'...
warning: You appear to have cloned an empty repository.
done.
# Criação do primeiro commit, necessario para ter um `git status` normal.
$ echo "txt" > file.txt && git add file.txt && git commit -m "Initial commit"
# A mensagem vá aparecer
$ git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working directory clean
# Verificando a ligacao `master` -> `origin/master`
$ git branch -vv
* master 8cbd8af [origin/master: gone] Initial commit
In your case, you have made other modifications, such as errors. First, update the remote Repository data:
git fetch origin
Checks which remote branches have in remote Repository, and checks connections:
git remote show origin
git branch -vv
If you created a bad branch, you can delete it with (example with branch test
):
git push origin :test
crio o remoto (remote)
what exactly do you do at this stage? When you clone a project (git clone) it already comes with the correct remote (origin). You’re adding another?– Ricardo Moraleida
Ricardo, I believe you killed the riddle. As I started with the recent git, I imagined that whenever I made a clone, I should already create a remote for the source I cloned, and in fact this remote is already created by default. Dai repeated the process using the already standard clone (origin) and the "error" did not happen anymore. Thanks.
– Paulo Luvisoto