There is a tag 1.2
and a branch exp
.
I can checkout the tag by git checkout 1.2
and it brings me in the detached head state which is fine. There is already a branch I have created on the server = exp
. The branch exp
is based on the master
. As of now master
(thus also exp
) are two commits ahead of 1.2
.
What I would like to do is start at 1.2
and retain all my future commits to the branch exp
.
However, when I do
git checkout 1.2 -b exp
I get an error
fatal: a branch named 'exp' already exists
I understand the logic behind this and I realize the practice is to create a new branch.
What I essentially want is to use the existing branch name exp
and not create a new branch. I don't care about if exp
is ahead or behind 1.2
As an example, the following timeline:
t = 0 --> checked out
1.2
t = 1 --> add new code to tag
1.2
. All this new code must sit on the existing branchexp
because I cannot commit on the tag.
t = 0 is clear for me but t = 1 is not.
git checkout exp
.git commit
to do in your hypothetical setup. Would that move the branch head and the tag? Or something else?exp
and1.2
point to different commits then yes, checking them out will move to different commits, obviously. But it's usually pretty clear which one you want, so if you want to somehow check out both at the same time, then you must have some behaviour in mind that you want to achieve (for example when you commit at that point) and that expectation is what I've been asking: describe what you want to achieve, and we might be able to point you in the right direction.1.2
then commit all changes to an existing branchexp
; irrespective of it being ahead or behind.exp
to point to the commit referenced by1.2
? Then you simply need to use-B
instead of-b
(it's a common pattern in git that upper-case flags do the same thing, but turn off some safety checks).