Git provides an explanation of what a detached HEAD is and what we can do from there.īasically, in that state, you can explore the code and even create new commits, but those changes would not be in sync Git indicates that we are now in a detached HEAD state. Turn off this advice by setting config variable tachedHead to false If you want to create a new branch to retain commits you create, you mayĭo so (now or later) by using -c with the switch command. Example: State without impacting any branches by switching back to a branch. You are in 'detached HEAD' state. You can look around, make experimentalĬhanges and commit them, and you can discard any commits you make in this (We’ll see later what happens if she forgets to do the git fetch beforehand).Īlina git:( main ) git checkout origin/b1 In order to access that new branch b1, a git fetch is required. Git indicates that everything is good: the local branch b1 in Blake’s repository is set up to track the branch origin/b1 on the origin server.Īt this stage, both commit graphs are the same between the origin and Blake’s repository:īlake 7d60b3c ebc4912 b1 main origin/b1 HEADīack on Alina’s machine, her Git repository still has the previous commit graph. Remote: Create a new pull request for 'b1': The git server also has the same commit tree:īlake creates a branch b1 using the git switch -c command (which also sets b1 as the current branch for her).īlake git:( b1 ) git push -set-upstream origin b1 They both start from the same commit graph. Let’s consider two developers, Alina and Blake, working on the same repository. Now, let’s see how this manifests in practice. If HEAD is instead a reference to an arbitrary commit, then you are in a detached HEAD state. In a normal situation, HEAD is a reference to the head of your current branch. This is particularly true for local branches, also known as heads, which are named references to the commit at the tip of the branch. However, these refs are not necessarily equivalent. ![]() Git uses their names to reference specific commits in the commit graph. ![]() The most notable example is HEAD.Ī branch, a remote branch, even a stash are all refs. There are a few special-purpose refs that do not begin with refs/. refs/heads/master) that points to an object name or another ref (the latter is called a symbolic ref). It is important to understand how Git manages refs in order to understand how some of the Git commands operate.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |