Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>So I can use the same command in svn/cvs to switch branches and publish changes?

No, it's about the notation for remotes and branches. It's confusing that sometimes when I refer to a branch I call it remote/branch and other times I call it remote branch. It would've been way more consistent if it were always remote/branch.

As a result, git push sometimes gets confusing. Suppose I'm on staging. I then say, git push heroku staging:master (push the staging branch to the master branch on heroku) whereas git push staging:heroku/master is imho easier to understand.



  > git push heroku staging:master
Without the shortcuts, this command would be:

  git push heroku refs/heads/staging:refs/heads/master
"refs/heads/master" is literally the branch location in the $GIT_DIR on the remote. You could do something like:

  git push heroku staging:refs/personal/phillmv/staging
to stick the branch in a non-standard location, or you could do:

  git push ssh://hostname/path/to/repo staging:staging
or:

  git push ~pyre/work/repo staging:pillmv-staging
to push to a location that you don't have specifically defined as a remote.

E.g.

  % cd /tmp
  % mkdir test1 test2
  % pushd test1
  % git init .
  Initialized empty Git repository in /tmp/test1/.git/
  % popd
  % pushd test2
  % git init .
  Initialized empty Git repository in /tmp/test2/.git/
  % git ci --allow-empty -m 'ini commit'
  [master (root-commit) 54ec2a3] ini commit
  % git push ../test1 master:test2-master
  Counting objects: 2, done.
  Writing objects: 100% (2/2), 168 bytes, done.
  Total 2 (delta 0), reused 0 (delta 0)
  Unpacking objects: 100% (2/2), done.
  To ../test1
   * [new branch]      master -> test2-master


Huh. Out of curiosity, why would I ever want to do this?

> git push heroku staging:refs/personal/phillmv/staging

Will it still appear in git branch lists?

I get what you're saying and I appreciate the lesson :).

Is there a reason for the syntax in checkout being remote/branchname then? I care about consistency more than the specific syntax.


  > Will it still appear in git branch lists?
By default, git will only pull branches out of refs/heads/* on the remote repo. You can configure it to do otherwise though. This allows you to store branches on the repo that not everyone will necessarily pull down into their repo. This is obviously less useful with a smaller group of developers and/or a private repository.

  > Is there a reason for the syntax in checkout
  > being remote/branchname then? I care about
  > consistency more than the specific syntax.
In git-checkout, you're resolving the branch name locally. When you sync to a remote, a copy of all branches from refs/heads on the remote repo are pulled down and stored in refs/remotes/$remote_name/branch_name. So, refs/heads/master on the remote repo is refs/remotes/origin/master locally.

The right side of the ':' in the git-push command resolves on the remote repo, but git-checkout resolves in your local repo.

Also look at the git-rev-parse manpage for info on the resolve order/etc for branch name shortcuts. It's the 3rd bullet point under 'Specifying Revisions.'




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: