Error: src refspec does not match

I have a project with several friends in GitLab, and, of course, the main branch, and there are others. When I cloned the repository, I also created an upstream with the git remote add upstream ... command.

Then I released git fetch upstream . This is followed by git checkout upstream/test1 . Now, if I type git branch -a , I get this output:

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

Everything is fine, but then I made some changes to the code in my upstream/test1 branch, and I want them to insert them into the origin/test1 repository, I get an error message in the header. Please note that I am doing the following steps:

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

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

 refs/heads/master refs/remotes/origin/HEAD refs/remotes/origin/master refs/remotes/upstream/test1 refs/remotes/upstream/master 

I checked the following questions , but did not find it useful. Any ideas how to solve it?

+6
source share
2 answers

You do not have a local branch named test1 . You have a remote branch named test1 associated with your upstream remote.

Do not directly edit the upstream/test1 branch. In fact, trying to verify this should have given 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. 

First you should check the local branch tracking the remote branch, which should 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 that, unecorated git push will click on the remote upstream , and git push origin test1 will click on your origin remote. Adding the -u flag will switch the tracking branch, so instead of tracking upstream/test1 your branch will track origin/test1 , so future git pull and git push operations relate to this remote branch ( origin/test1 ) by default.

+2
source

The following will create a new branch both locally and remotely. I follow this when I create a new branch for work.

git check wizard

git main source of traction

git checkout -b your-branch

Make new changes

git push -u origin your-branch

0
source

Source: https://habr.com/ru/post/1011622/


All Articles