3

I added new remote based on some online information that I have collected. My commands are

git remote add gitlab  http://ankits@abc.xyz/janedoe/my.git
git push gitlab master -f

But when I do

git branch -a

*master
sprint_2
sprint_3
remote/gitlab/master
remote/origin/HEAD -> origin/master
remote/origin/sprint_2
remote/origin/sprint_3
remote/origin/sprint_1

How come I don't see branches sprint_2/3/1 in my gitlab remote?

cantSleepNow
  • 9,691
  • 5
  • 31
  • 42
Romeo
  • 147
  • 1
  • 3
  • 11
  • 1
    You only pushed one branch to the remote *gitlab*, didn't you? You have two remotes linked to your local repo: origin, the remote you already had before, with 4 branches and the new one, where you pushed master branch. Are there supposed to be more branches on http://ankits@abc.xyz/janedoe/my.git? If so, do `git fetch gitlab` – Manuel Schmidt Aug 15 '17 at 19:29
  • no..there are no branch in 'gitlabl remote. My purpose for setting up new remote is to use it for Continuous integration/Continuous development using GItLab tools. So every time I push something, it triggers a pipleline on GitLab and run regression. – Romeo Aug 15 '17 at 21:36
  • Have a look at the `--mirror` option, but be careful it implies the `--force` option. – Manuel Schmidt Aug 15 '17 at 21:45
  • so I added mirror option to git remote add --mirror=fetch gitlab , but it's not working. Also, when I push changes from local master, it only shows up in origin/master. It's not showing up in gitlab/master. – Romeo Aug 15 '17 at 22:10
  • https://git-scm.com/docs/git-push – Manuel Schmidt Aug 15 '17 at 22:18
  • Nevertheless if you want to duplicate the repo in GitLab, maybe it's better doing it this way: https://help.github.com/articles/duplicating-a-repository/. Otherwise you only push local branches, except you push explicitly remote branches from origin/* – Manuel Schmidt Aug 15 '17 at 22:31

2 Answers2

8

this undesired behavior probably occur because the current branch has no upstream branch. To push the current branch and set the remote as upstream, use:

git push --set-upstream origin <your-branch-name>
Farlon Souto
  • 116
  • 1
  • 6
0

When you run

git push gitlab master

you specifically ask Git to push the master branch.

If you wish to push all branches to your new gitlab remote you can run git push gitlab --all:

Push all branches (i.e. refs under refs/heads/); cannot be used with other .

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Thanks Chris! that works! Problem is now if commit and push, my orgin remote branch is also updated, but looks like my new remote branch - gitlab is not updated. What am I missing? – Romeo Aug 15 '17 at 21:27
  • 1
    With `git branch -vv` you can see where a branch is pushed to by default. You can change it with `git branch master --set-upstream-to=gitlab/master` – Manuel Schmidt Aug 15 '17 at 21:52
  • Thanks. Can I push upstream to origin/master and gitlab/master – Romeo Aug 15 '17 at 22:08
  • 1
    `git push origin master:master` pushes the local master branch to origin/master `git push gitlab master:master` pushes it to gitlab/master – Manuel Schmidt Aug 15 '17 at 22:12
  • 1
    @Romeo, if you want `git push` to automatically update multiple remotes you [can configure it to do so](https://stackoverflow.com/q/14290113/354577). – ChrisGPT was on strike Aug 16 '17 at 18:34
  • @Romeo if this worked, consider accepting the answer – eis Jan 16 '18 at 14:03