On Sun, Aug 05, 2012 at 02:00:33AM -0700, THUFIR HAWAT wrote:

> I'm not quite clear on how to branch.  If I'm in the master, commit and 
> push, so that everything is up to date, and then create a branch, how do I 
> push that branch?

$ git push <remote> <thatbranch>

will push the branch <thatbranch> to the remote <remote>.

> I don't see this scenario described at 
> http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging where 
> the master is up to date and then a branch is created.
> 
> Granted, I can checkout that new branch, make a silly change, commit and 
> push that branch, but that seems, well, silly.  What's the better approach?
You seem to think that `git push` can only be called with one argument
(the name of the remote) or without any arguments at all.
In this mode, the behaviour of `git push` is controlled by the
"push.default" configuration option [1], which currently defaults to
"matching" [2].  In the "matching" mode `git push` attempts to push only
those branches which have the same-named branches on the remote
repository.  The end result is that if you create a branch which has a
name not matching any branches in the remote repo, it won't be attempted
to be pushed; you have to do that manually.
If you think about this a bit more, you'll find this quite logical:
the key idea when working with Git is that your local repository is your
very personal playground--you can quickly create branches and get rid of
them without ever needing to hit any remote server.  So when you think
you want to push something to a remote repo, you have to think first and
then push exactly what you want and how you want to do that.

If you think your new branch is going to have a prolonged life in the
remote repo, it's usually a good idea to use the "-u" command-line
option with an initial `git push` to instantly create a so-called
"remote branch" in your local repository for that new branch and make
your branch track it.  I mean, if you created a branch named "foo" and
intend to push it to your "origin" remote, specifying the "-u"
command-line option to the `git push` will automatically create a
"origin/foo" branch for you and set the "foo" branch to track
"origin/foo".  I do understand this sounds complicated, so if you can't
grok it just now, read about remote branches first [3].

In general, you should make yourself familiar with the fact `git push`
is able to perform fine-grained pushes (and even deletion of remote
objects) by crafting an appropriate "refspecs" for its invocation.
For instance, you can push a branch named "foo" to a branch named "bar"
in a remote repo.  Or you can push a tag to a branch, or even a SHA-1
name of a commit to a branch.  You can also update remote tags with
arbitrary objects; you can push the HEAD directly anywhere etc.
Read more on it in [4] and [5].

1. Refer to the `git config` manual page.
2. This will probably change, read up about the new mode, "simple",
   and the intent to make it the default, eventually, here:
   https://raw.github.com/git/git/master/Documentation/RelNotes/1.7.11.txt
3. http://git-scm.com/book/en/Git-Branching-Remote-Branches
4. http://git-scm.com/book/en/Git-Internals-The-Refspec
5. http://git-scm.com/ref/git-push

-- 
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-users@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