Skip to content

Instantly share code, notes, and snippets.

@jdunck
Created May 16, 2016 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdunck/8521eb0c00f81840e790dbcd2b0462f3 to your computer and use it in GitHub Desktop.
Save jdunck/8521eb0c00f81840e790dbcd2b0462f3 to your computer and use it in GitHub Desktop.
Git tags are repo-wide
mbp3:junk jdunck$ mkdir test
mbp3:junk jdunck$ cd test/
mbp3:test jdunck$ git init
Initialized empty Git repository in /Users/jdunck/junk/test/.git/
mbp3:test jdunck$ echo x > derp
mbp3:test jdunck$ git add derp
mbp3:test jdunck$ git commit -m "Initial"
[master (root-commit) 818e7a7] Initial
1 file changed, 1 insertion(+)
create mode 100644 derp
mbp3:test jdunck$ git checkout -b branch-a HEAD
Switched to a new branch 'branch-a'
mbp3:test jdunck$ git checkout -b branch-b HEAD
Switched to a new branch 'branch-b'
mbp3:test jdunck$ echo y > branch-b
mbp3:test jdunck$ git add branch-b
mbp3:test jdunck$ git commit -m "b"
[branch-b 90f10ea] b
1 file changed, 1 insertion(+)
create mode 100644 branch-b
mbp3:test jdunck$ git checkout branch-a
Switched to branch 'branch-a'
mbp3:test jdunck$ echo y > branch-a
mbp3:test jdunck$ git add branch-a
gmbp3:test jdunck$ git commit -m "a"
[branch-a e3a23ec] a
1 file changed, 1 insertion(+)
create mode 100644 branch-a
mbp3:test jdunck$ git status
On branch branch-a
nothing to commit, working directory clean
# make a tag 1.0 w/o referencing a commit, makes it on current HEAD, which is on branch A.
mbp3:test jdunck$ git tag 1.0
# switch to branch b, try to make a 1.0 on it, but it will fail:
mbp3:test jdunck$ git checkout branch-b
Switched to branch 'branch-b'
mbp3:test jdunck$ git tag 1.0
fatal: tag '1.0' already exists
# check out 1.0, and verify that it shows the HEAD of branch-a:
mbp3:test jdunck$ git checkout 1.0
Note: checking out '1.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at e3a23ec... a
mbp3:test jdunck$ git log
commit e3a23ec104b73a0f73bd43aa551530c301ed027e
Author: Jeremy Dunck <jdunck@gmail.com>
Date: Mon May 16 12:47:17 2016 -0700
a
commit 818e7a7c73141bcb40424beb1f6f3c798bd82bc7
Author: Jeremy Dunck <jdunck@gmail.com>
Date: Mon May 16 12:46:15 2016 -0700
Initial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment