6

While waiting for the sysadmin to set up the gerrit repo, I made my own branch. He just now sent me the address of the repo. I set it for origin and somehow pushed my last commit. Cloning the repo works fine, however git branch -r returns nothing. What is going on here?

$ git init
# made some comits    
git config remote.origin.url ssh://gerrit.mm-sol.com/branchname

$ git push origin SH1-of-my-last-commit:master    
error: unable to push to unqualified destination: master    
The destination refspec neither matches an existing ref on the remote nor  
begins with refs/, and we are unable to guess a prefix based on the source ref.  
error: failed to push some refs to 'ssh://gerrit.mm-sol.com/apps/phone-shaker'  

$ git push origin master
Counting objects: 85, done.  
Delta compression using up to 4 threads.  
Compressing objects: 100% (85/85), done.  
Writing objects: 100% (85/85), 20.95 KiB, done.  
Total 85 (delta 49), reused 0 (delta 0)  
remote: Resolving deltas: 100% (49/49)   
remote: Updating references: 100% (1/1)  
To ssh://gerrit.mm-sol.com/branchname  
 * [new branch]      master -> master  
Vorac
  • 8,726
  • 11
  • 58
  • 101
  • Try `git fetch origin` and then `git branch -r` again. – Amber Sep 25 '12 at 08:07
  • If you have not pushed anything there yet, the cloned repo wont show any branch. It should have after the last command, though. – fork0 Sep 25 '12 at 08:09
  • @Amber: `git push` updates both remote and remote tracking (the local branch pointer, matching the remote) branch pointers – fork0 Sep 25 '12 at 08:10
  • @Amber, * branch master -> FETCH_HEAD. Still git branch -r returns nothing. – Vorac Sep 25 '12 at 08:24

2 Answers2

25

Try this:

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin

and then try git branch -r again.

In the future when setting up remotes, it's preferable to use the following command instead of git config:

git remote add <remotename> <remoteurl>

e.g.

git remote add origin ssh://gerrit.mm-sol.com/branchname

This will automatically set up both the url and fetch configuration.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Another problem solved :) I am used to cloning repo-s and was doing this thing for the first time. Tahnks a lot, Amber! – Vorac Sep 25 '12 at 10:00
1

Try to git push -u origin master

whoan
  • 8,143
  • 4
  • 39
  • 48
Tim
  • 2,006
  • 2
  • 18
  • 25
  • Ah, right. If the `git remote add` were used, it would have been done, but the setup command was somewhat incomplete: `git config remote.origin.url ...` – fork0 Sep 25 '12 at 08:12
  • mvitkov@mms:~/projects/myproject$ git push -u origin master Branch master set up to track remote branch master from origin. Everything up-to-date. However, git branch -r still returns nothing! – Vorac Sep 25 '12 at 08:21