Git Help

Coleman Kane ckane at colemankane.org
Wed Mar 10 11:46:49 EST 2010


Do't use 'git branch' any more for creating new branches, instead use
'git checkout'.

>From your description, I think I know what you are looking for. Consider
the following example where you edit the file 'test.c' and want to
commit those changes to a new branch named 'branch-2' rather than the
current branch ('master').

In your git-managed source repository, edit the file 'test.c' and save
it.

Then, run (this will create a new branch 'branch-2' from the current
working branch):
  git checkout -b branch-2

Your file 'test.c' will still remain "edited", but the .git repo will
have 'branch-2' now which is almost identical to 'master' (same rev
history). You will automatically be operating o 'branch-2' instead of
'master' when the operation completes.

Add the changes to 'test.c' to the present branch ('branch-2'):
  git add test.c

Finally, commit these additions to the present branch ('branch-2'):
  git commit


To switch back to branch 'master':
  git checkout master

To switch back to branch 'branch-2':
  git checkout branch-2

The output of these two will differ:
  git log master
  git log branch-2

The latter should have your edits, while the former will not.


Beware the HOWTO's out there, as the above sequence is the 'new way' of
doing this in git. The old way actually used 'git branch' for all the
branching operations and was more clumsy. This change happened within
the past two years.

-- 
Coleman Kane


On Wed, 2010-03-10 at 11:30 -0500, Thomas Charron wrote:
> As a git newb, I've got a couple of questions about git which
> confuse me.  Any git users who might be able to explain?
> 
>   If I'm in a directory and have made local modifications, and then I
> issue a git branch, what does the branch contain a copy of if I check
> it out?  The latest head?  Or does the branch branch whatever I'm
> working on to a new branch, which contains a copy of the state of the
> original branch?
> 




More information about the gnhlug-discuss mailing list