-1

I created "my_branch" while I was on "release"

git branch my_branch release    

So now I have this:

$ git branch
my_branch
master
* release

I do some adds and commits. Then, I want to push my_branch, but I expect it to be at the same level as release, and not at the origin / HEAD. But that's what happen, if I do:

git push origin my_branch

What is the correct command to have "my_branch" out of "release" ?

--------------------------- EDIT

If I do my add/commit after a first push:

git push origin my_branch
git checkout my_branch
git add myfile.txt
git commit -a -m"toto"
git push

fatal: The current branch my_branch has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin my_branch

--------------------------- EDIT 2

git branch my_branch release
git push origin my_branch
git checkout my_branch
git add myfile.txt
git commit -a -m"toto"
git push origin my_branch

This works. It is showing up as a fork out of release after the first push in gitlab. After the second push, the commits is shown as head, ahead of master. I now understand what is hapening looking at the gitlab view. The original scenario at the top actually works but I had trouble interpreting it.

Bob Yoplait
  • 2,322
  • 1
  • 22
  • 34
  • What is the problem with the command, exactly? Did you create additional commits on release that are not visible on my_branch? If not, the command should do exactly what you describe you want done. – user4815162342 Oct 12 '14 at 08:11
  • Are you still on `master` or something? – Qantas 94 Heavy Oct 12 '14 at 08:13
  • The problem is in gitlab network graph, I would expect my branch to be "a fork" out of "release". But my git understanding may be wrong. – Bob Yoplait Oct 12 '14 at 08:13

1 Answers1

1

What is the correct command to have "my_branch" out of "release" ?

git push origin my_branch will work: it will create a branch 'my_branch' in the remote repo origin, even though that branch will reference the same commit as the release branch.
It will still be a branch independent from release.

It won't show a 'fork' in the history of commits in your GitLab server.
It will only show a fork if you:

  • git checkout my_branch,
  • git add and git commit,
  • git push origin my_branch again.

The first push might necessitate that you define an upstream branch:

 git push --set-upstream origin my_branch
 or for more recent git
 git push -u origin my_branch
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • @BobYoplait yes, the first push will require to set an upstream branch: see http://stackoverflow.com/a/17096880/6309 – VonC Oct 12 '14 at 08:30