On Jul 28, 10:00 pm, joe <ehass...@gmail.com> wrote:

> When going through several articles/tutorials about git I see the
> following being done for the initial push to a new branch:
>
> git push origin branchname:refs/heads/branchname
>
> Is this necessary for subsequent pushes or does "git push" do the same
> thing?  I just tested this with a couple of dummy repo's and it seems
> to do the same thing.  I've actually been doing this each time I need
> to add/push something new to branches that aren't touched by
> developers:
>
> ** add files **
> git add .
> git commit -am "added foo"
> git push origin branchname:refs/heads/branchname
>
> ** checkout branch that is worked on and pull new data from branchname
> **
> git checkout devbranch
> git pull . branchname
> git push origin devbranch:refs/heads/devbranch
>
> So, if anyone could clarify this for me that would be awesome :)

First, the "refs/heads/" prefix is superficial for most cases and is
only really needed when you have ambigous names (say, tag names
clashing with branch names). See the "SPECIFYING REVISIONS" section in
git-rev-parse manual page for the precise description of how such an
"unprefixed" name is revolved.
In other words, you usually just do `git push origin
devbranch:devbranch`.

Second, in most cases you will also omit the part after ":" (and the
colon itself) because if you do this, the destination ref name is
assumed to be the same as source. In other words, this usually can be
stripped down to `git push origin devbranch`.
Both refspecs are only needed when you want to update a remote ref
with a local ref which has different name, say, you fetched branch
"foo" from the remote, forked a local branch "bar" off it, made
several commits on it and then want to update the remote "foo" with
the fresh stuff in "bar"; in this case you do `git push origin
bar:foo`.

About the second question: no, nothing is "saved" automatically (which
is good).
On the one hand, you should be careful about what you push and so
naming refs explicitly is good, not hard. On the other hand, if you
need "mirror" mode, just use "--mirror" or other means. git-push
manual is your friend; read in thoroughly.
Also you can modify the behaviour of push in some ways, see
"push.default" parameter and parameters starting with "branch." in git-
config manual.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-us...@googlegroups.com.
To unsubscribe from this group, send email to 
git-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/git-users?hl=en.

Reply via email to