Push problem of a new branch to gitlab

Hello,

I’m testing a local GitLab Community Edition [14.0.1] installation on an Ubuntu 20.04 system and ran into the following problem.

  • I created a blank project in gitlab using the gitlab user interface.

  • In my home directory on Ubuntu I created a git repository and populated it with some files.

$ mkdir great-test-project
$ cd great-test-project
$ git init
$ vi README.md
#####-First test-########
$ git add README.md
$ git commit -m “Initial commit”

  • I pushed the local git repository to the earlier created empty gitlab repository

$ git remote add origin git@gitlab1.vhel.invalid:vhelmont/great-test-project.git
$ git push -u origin master

  • I created an issue in the newly created gitlab project using the gitlab user interface.

  • In the local git repository on my Ubuntu home directory, I created a branch to fix the issue, adjusted a file, performed a git add and a git commit

$ git checkout -b problem_fix
$ vi README.md
#####-First test-########
#####-Problem fix-########
$ git add README.md
$ git commit -m “Fix commit”

  • Then I tried to push the “problem_fix” branch to the gitlab repository and start a merge request

  • The push failed with the error message:

$ git push -u origin problem_fix
error: src refspec problem_fix does not match any
error: failed to push some refs to ‘git@gitlab1.vhel.invalid:vhelmont/great-test-project.git’
$

Any idea what I did wrong?

Regards,
Albert

What do you get with git push origin problem_fix?

Hello snim2,
Thanks for the tip, it indeed solved the problem.
I’m new to git and gitlab can you also explain why the -u version of the command failed?
Regards,
Albert

git push --help says this:

       -u, --set-upstream
           For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands. For more information, see branch.<name>.merge
           in git-config(1).

So with -u you are setting an upstream branch. What you wanted to do, was to use the upstream branch that was already set, and push your new commits to it.

TBH I’ve never used -u before, but Git is vast, and has many, many options. It would probably benefit you to read a tutorial or two (there are many around, including some from GitLab) and in particular one that covers merge requests (you may see “pull requests” more frequently, but are essentially the same thing).

Thanks for the advise.
Regards,
Albert