Git Tutorial 7: What is HEAD?
Key Takeaways
Explains what HEAD is in Git version control system
Full Transcript
Dear friends, in this tutorial we are going to learn what is head in git. Head is a reference to the most recent commit in the current branch in most of the cases. The reason I said most of the cases is because there are some cases where uh this is not the case and we will cover them later on. I have this git repository where I have bunch of commits which I can list using git log. Okay. Okay. So I have these three comets. Now head is nothing but a reference to this comet. Uh I can verify by running this command called get show head. This will show me the head commit. This is same as doing get show this particular commit. Okay. So they produce the same output. So I can say head is just a short form of writing this commit. Okay. Now let me make one more commit and see what happens to get. So I'm going to add one more line here and I will commit that change. So I added this and I will now commit this. Okay. So get commit minus m burger. Okay. When I do that uh and if I run get log I say this commit and when I do get show head it will now show me burger commit. So as you can see in the diagram the head pointer keeps on moving and it always not always but in majority of the cases it refers to the most recent comet. Okay. Now let me show you another another case where head had head could be useful and that is to do the diff. Now we have been running this get diff tool command in our previous tutorial. So this uh command is useful to show the difference between two commits. Okay. So I'm going to run gift get diff to run two commits. So for example uh from this commit to this commit this pizza line was added. Okay. And I want to see the difference between the snapshot of this and this. So the way you do it is by running get diff tool the older commit which is this. So I'm just going to copy paste that commit and the newer commit which is this. So again I'll be copying and pasting. When I do that uh the mold diff tool will open and it will show me the difference from left and right. You see this pizza line was added between those two commits. So this is my old code. This is my new code. Okay. Now the same thing you can do by using a head. So I can say head. Now remember head is here. So this comet will be head tilda one and this commit will be head tilda 2. So you always put uh the older commit first. So I will do head tilda 2 and held uh tilda one. You can just say like head minus two you know this is one and this is this is head this is head minus one head minus two so head minus 2 and head minus one okay and when you do that you will get the same output you'll see that in this particular commit pizza line was added okay so this command is just a short form of running this but the benefit here is that you don't have to remember the commit or copy paste this wrong commit ID you can just use this short form. So head h a refers to this head my head tilda one refers to this head tilda 2 refers to this particular commit id. Okay now u let's see how g internally manages this head pointer. Uh if you have your code repository open and if you have if you're showing uh the hidden repos hidden directories then there is always a directory in your current code directory. If this is not visible you can go to windows explorer option and choose the option to show hidden files. Okay but once you have directory open you will see bunch of files here and head is one of the files. Now when I open this head file I will see this. So it is referring to a master branch. Now if I have two branches uh for example I have when I do get branch I have second branch called thirsty. Now when I check out the second branch my head pointer will actually move to thirsty. So see now it updated this file and now I have thirsty uh in my head. Okay. Now let me discuss the scenario where head doesn't point to the most recent commit. That scenario is called detached head. So sometimes uh when you do get log you want to go to this previous commit. Okay. And based on that previous commit you want to make some changes. So you want to make this particular commit your base and then want to add further changes because you want to ignore this. In that case you will do get check out this commit. Okay. And let's see what happens when we run this command. Okay. It is showing me this message that you are in detached head state. Meaning head is not pointing to the most recent commit. it is at some older commit. Okay. And you can see that reflected here as well. Usually it's a branch name but now it is this particular thing. Okay. So um now your head is in a detached state and when I open my head file head is having this commit ID 4 BC etc. And that was this commit ID 4 BC etc. So you can see how git manages all of these things by using a simple text file. Okay. All right. So now I want to come out of the detached head state. In that case you can do get checkout master. And now you are at master. The pizza is the most recent commit. And when you do that you will come out of the detached head state. All right. Okay. So, that was all about head. Thank you for watching this video.
Original Description
Simple git tutorial explaining what is HEAD in git version control system.
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Git Tutorial: https://www.youtube.com/watch?v=xAAmje1H9YM&list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW
Next Video:
Git Tutorial 8 - .gitignore file: https://www.youtube.com/watch?v=ErJyWO8TGoM&list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW&index=8
Machine Learning Tutorial With Python: https://www.youtube.com/watch?v=gmvvaobm7eQ&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw
Website: https://codebasics.io/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from codebasics · codebasics · 50 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
▶
51
52
53
54
55
56
57
58
59
60
Python Tutorial - 1. Install python on windows
codebasics
Python Tutorial - 2. Variables
codebasics
Python Tutorial - 3. Numbers
codebasics
Python Tutorial - 4. Strings
codebasics
Python Tutorial - 5. Lists
codebasics
Python Tutorial - 6. Install PyCharm on Windows
codebasics
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
Python Tutorial - 8. If Statement
codebasics
Python Tutorial - 9. For loop
codebasics
Python Tutorial - 10. Functions
codebasics
Python Tutorial - 11. Dictionaries and Tuples
codebasics
Python Tutorial - 12. Modules
codebasics
Python Tutorial - 13. Reading/Writing Files
codebasics
How to install Julia on Windows
codebasics
Python Tutorial - 14. Working With JSON
codebasics
Julia Tutorial - 1. Variables
codebasics
Julia Tutorial - 2. Numbers
codebasics
Python Tutorial - 15. if __name__ == "__main__"
codebasics
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
Python Tutorial - 16. Exception Handling
codebasics
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
Julia Tutorial - 4. Strings
codebasics
Python Tutorial - 17. Class and Objects
codebasics
Julia Tutorial - 5. Functions
codebasics
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
Julia Tutorial - 7. For While Loop
codebasics
Python Tutorial - 18. Inheritance
codebasics
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
Julia Tutorial - 10. Exception Handling
codebasics
Python Tutorial - 19. Multiple Inheritance
codebasics
Python Tutorial - 20. Raise Exception And Finally
codebasics
Python Tutorial - 21. Iterators
codebasics
Python Tutorial - 22. Generators
codebasics
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
Python Tutorial - 24. Sets and Frozen Sets
codebasics
Python Tutorial - 25. Command line argument processing using argparse
codebasics
Debugging Tips - What is bug and debugging?
codebasics
Debugging Tips - Conditional Breakpoint
codebasics
Debugging Tips - Watches and Call Stack
codebasics
Python Tutorial - 26. Multithreading - Introduction
codebasics
Git Tutorial 3: How To Install Git
codebasics
Git Tutorial 1: What is git / What is version control system?
codebasics
Git Tutorial 2 : What is Github? | github tutorial
codebasics
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
codebasics
Git Tutorial 9: Diff and Merge using meld
codebasics
Difference between Multiprocessing and Multithreading
codebasics
Python Tutorial - 27. Multiprocessing Introduction
codebasics
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
Git Tutorial 8 - .gitignore file
codebasics
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
Python Tutorial - 30. Multiprocessing Lock
codebasics
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
What is code?
codebasics
Python unit testing - pytest introduction
codebasics
Related AI Lessons
⚡
⚡
⚡
⚡
Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Medium · AI
Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Medium · Data Science
Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Medium · Deep Learning
Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Medium · LLM
🎓
Tutor Explanation
DeepCamp AI