Re: How to create & switch to a branch after changes have already been made?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The magic you're looking for is "git checkout -b <branch>"

You can do that even with uncommitted changes hanging around.
Because you don't specify a commit to check out, it just "checks out
the HEAD again", which does nothing.  The only thing left is the
part that creates and switches to a new branch.

Now, if you've already created the branch, you can either do:
git checkout <newbranch>
which, since <newbranch> equals HEAD, just switches the HEAD symlink
without actually changing the checked-out commit.

Or, if you want to be really low-level,

git-update-ref HEAD <newbranch>

Which is the underlying tool that git checkout uses.
It bypasses all the safety checkes, but it might be easiest to understand.


Now, if you've already committed, you can just do:

git checkout -b <newbranch>
git branch -f <oldbranch> HEAD^


Admittedly, I sometimes with for a "git commit -b <branch>" shortcut.
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux