typos typos - 3 years ago 694
Git Question

Error: src refspec does not match any

I have a project with a few friends in GitLab, and there is of course the master branch, and there are some others too. When I cloned the repository, I created also an upstream with the command

git remote add upstream ...

Then, I issued the
git fetch upstream
. Followed by
git checkout upstream/test1
. Now, if I type
git branch -a
, I get an output like this:

* (HEAD detached at upstream/test1)
remotes/origin/HEAD -> origin/master

This is all fine, but then I did some changes to the code in my
branch, and I want to push them to
repository, I get the error message on the title. Please note that I follow the steps below to push:

git add .
git commit -m "Sample message"
git push -u origin test1

If I issue
git show-ref
, I get the following output:


I checked the following questions, but didn't find it helpful. Any ideas how to solve it?

Answer Source

You don't appear to have a local branch named test1. You have a remote branch named test1 associated with your upstream remote.

You shouldn't be editing the upstream/test1 branch directly. In fact, attempting to check that out should have yielded a warning:

$ git checkout upstream/test1

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

You should instead first check out a local branch that tracks the remote branch, which ought to look something like this:

$ git checkout test1
Branch test1 set up to track remote branch test1 from upstream by rebasing.
Switched to a new branch 'test1'

After doing this, an undecorated git push would push to the upstream remote, while git push origin test1 would push to your origin remote. Adding the -u flag there would switch the tracking branch so that instead of tracking upstream/test1, your branch would track origin/test1, so that future git pull and git push operations would refer to that remote branch (origin/test1) by default.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download