1

Which push Refspec (Git) is correct? Or both are correct? What is the difference?

  1. refs/heads/*:refs/heads/origin/*
  2. refs/heads/*:refs/heads/*

I prefer (1) because it references remote name (origin), and I don't understand what (2) means (but I see it used in some manuals!).

Code Complete
  • 3,146
  • 1
  • 15
  • 38

1 Answers1

2

With refs/heads/*:refs/heads/origin/*, git push origin master would be expanded to git push origin refs/heads/master:refs/heads/origin/master. It will create or update a branch named origin/master in the remote repository. It's valid, but refs/heads/origin/master would be ambiguous with refs/remotes/origin/master. In some situations, it might cause errors.

The 2nd is valid. With remote.origin.push=refs/heads/*:refs/heads/*, git push is expanded to git push origin refs/heads/master:refs/heads/master refs/heads/dev:refs/heads/dev, and git push origin master to git push origin refs/heads/master:refs/heads/master.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • Sorry very much! Of course I meant `refs/heads/*:refs/heads/origin/*` for (1) – Code Complete Jun 12 '19 at 13:51
  • 1
    @CodeComplete With `refs/heads/*:refs/heads/origin/*`, `git push origin master` would be expanded to `git push origin refs/heads/master:refs/heads/origin/master`. It will create or update a branch named `origin/master` in the remote repository. It's valid, but `refs/heads/origin/master` would be ambiguous with `refs/remotes/origin/master`. In some situations, it might cause errors. – ElpieKay Jun 12 '19 at 13:54