Dear Sirs, there is a problem with a commit in git (specifically, in a gitlab)

See what I want to do:

There is a project, I make myself a local copy ( git clone )

Then, I want to make changes and commit and push them, but not to the master , but to the new branch .

When I make a change, everything is fine. when I try to push , I get an error. This is a short version.

Here are the details:

1) do git clone

2) make changes

3) through the WEB-interface of gitlab I make a new brunch. Called TstBranch

4) do git commit -m "Что я сделал - подробный комментарий"

5) check git status - beauty! You can give a letter. All files are there and everything is in place. It is this file set that I want to push through to the server.

6) do git push -u origin TstBranch

getting an error

 c:\Projects\TradingG0_Solution>git push -u origin TstBranch error: src refspec TstBranch does not match any. error: failed to push some refs to 'https://tst@GitLab0.junecat.ru/konst/TradingG0_Solution.git' 

For reliability, I attach two screenshots, which show all these commands that I performed and their results.

How would I do all the same commit and push to the correct branch? screenshot 1

screenshot 2

    1 answer 1

    Judging by your screenshots and according to your words, you always work in the master branch, you had to create a new branch (which you did), go to it (which you did not do), through git console for example this is done like this:

     git checkout -b TstBranch 

    And then being already on this branch to make changes and pour them out, and so it turns out that all this time you tried to pour out the master think that this is another branch.

    To prevent this from happening again, check the current branch with the command:

     git status 

    Switch between branches with the command:

     git checkout name 
    • Thank you very much! The answer helped me, learned to switch between branches! It was also important to see where to look at the output of the git status command in order to see the current branch. - SH
    • @SH I advise you to put Smartgit or SourceTree or analogs, I use option 1, it is more convenient for me. Although the server has to do the same with the hands - Yaroslav Molchan
    • Thanks, my work mostly happens in Visual Studio (2015), and I went to the command line to better understand Git and GitLab. Then I will return to the graphical environment, when I understand what is going on, and I will make commits with a single button - “on the knurled path”. The problem I am facing now is strange: I set up GitLab myself, according to the guidelines from the GitLab site. And there one of two protocols can be used to access projects: native git or https. So, for HTTPS everything works. And on the Git protocol, I get the error "Permission denied, please try again" - SH
    • @SH was also such a problem when I set it up, I don’t remember how I decided, I opened ports, but actually we use https and there were no problems - Yaroslav Molchan
    • And you can clarify: when you opened the ports (most likely, you only need port 22) - then the problem was solved? check is simple: try to clone the project on git - protocol from the whole gitLab. I wrote a detailed question on this topic: www.stackoverflow.com/questions/679220/… - SH