Git Tutorial 7: What is HEAD?

codebasics · Beginner ·📐 ML Fundamentals ·9y ago

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 Python Tutorial - 1. Install python on windows
Python Tutorial - 1. Install python on windows
codebasics
2 Python Tutorial - 2. Variables
Python Tutorial - 2. Variables
codebasics
3 Python Tutorial - 3. Numbers
Python Tutorial - 3. Numbers
codebasics
4 Python Tutorial - 4. Strings
Python Tutorial - 4. Strings
codebasics
5 Python Tutorial - 5. Lists
Python Tutorial - 5. Lists
codebasics
6 Python Tutorial - 6. Install PyCharm on Windows
Python Tutorial - 6. Install PyCharm on Windows
codebasics
7 PyCharm Tutorial - 7. Debug python code using PyCharm
PyCharm Tutorial - 7. Debug python code using PyCharm
codebasics
8 Python Tutorial -  8. If Statement
Python Tutorial - 8. If Statement
codebasics
9 Python Tutorial - 9. For loop
Python Tutorial - 9. For loop
codebasics
10 Python Tutorial -  10. Functions
Python Tutorial - 10. Functions
codebasics
11 Python Tutorial - 11. Dictionaries and Tuples
Python Tutorial - 11. Dictionaries and Tuples
codebasics
12 Python Tutorial - 12. Modules
Python Tutorial - 12. Modules
codebasics
13 Python Tutorial - 13. Reading/Writing Files
Python Tutorial - 13. Reading/Writing Files
codebasics
14 How to install Julia on Windows
How to install Julia on Windows
codebasics
15 Python Tutorial - 14. Working With JSON
Python Tutorial - 14. Working With JSON
codebasics
16 Julia Tutorial - 1. Variables
Julia Tutorial - 1. Variables
codebasics
17 Julia Tutorial - 2. Numbers
Julia Tutorial - 2. Numbers
codebasics
18 Python Tutorial - 15. if __name__ == "__main__"
Python Tutorial - 15. if __name__ == "__main__"
codebasics
19 Julia Tutorial - Why Should I Learn Julia Programming Language
Julia Tutorial - Why Should I Learn Julia Programming Language
codebasics
20 Python Tutorial  - 16. Exception Handling
Python Tutorial - 16. Exception Handling
codebasics
21 Julia Tutorial - 3. Complex and Rational Numbers
Julia Tutorial - 3. Complex and Rational Numbers
codebasics
22 Julia Tutorial - 4. Strings
Julia Tutorial - 4. Strings
codebasics
23 Python Tutorial -  17. Class and Objects
Python Tutorial - 17. Class and Objects
codebasics
24 Julia Tutorial - 5. Functions
Julia Tutorial - 5. Functions
codebasics
25 Julia Tutorial - 6. If Statement and Ternary Operator
Julia Tutorial - 6. If Statement and Ternary Operator
codebasics
26 Julia Tutorial - 7. For While Loop
Julia Tutorial - 7. For While Loop
codebasics
27 Python Tutorial  - 18. Inheritance
Python Tutorial - 18. Inheritance
codebasics
28 Julia Tutorial - 8. begin and (;) Compound Expressions
Julia Tutorial - 8. begin and (;) Compound Expressions
codebasics
29 Python Tutorial - 12.1 - Install Python Module (using pip)
Python Tutorial - 12.1 - Install Python Module (using pip)
codebasics
30 Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
Julia Tutorial - 9. Tasks (a.k.a. Generators or Coroutines)
codebasics
31 Julia Tutorial - 10. Exception Handling
Julia Tutorial - 10. Exception Handling
codebasics
32 Python Tutorial  - 19. Multiple Inheritance
Python Tutorial - 19. Multiple Inheritance
codebasics
33 Python Tutorial - 20. Raise Exception And Finally
Python Tutorial - 20. Raise Exception And Finally
codebasics
34 Python Tutorial - 21. Iterators
Python Tutorial - 21. Iterators
codebasics
35 Python Tutorial - 22. Generators
Python Tutorial - 22. Generators
codebasics
36 Python Tutorial - 23. List Set Dict Comprehensions
Python Tutorial - 23. List Set Dict Comprehensions
codebasics
37 Python Tutorial - 24. Sets and Frozen Sets
Python Tutorial - 24. Sets and Frozen Sets
codebasics
38 Python Tutorial - 25. Command line argument processing using argparse
Python Tutorial - 25. Command line argument processing using argparse
codebasics
39 Debugging Tips - What is bug and debugging?
Debugging Tips - What is bug and debugging?
codebasics
40 Debugging Tips - Conditional Breakpoint
Debugging Tips - Conditional Breakpoint
codebasics
41 Debugging Tips - Watches and Call Stack
Debugging Tips - Watches and Call Stack
codebasics
42 Python Tutorial - 26. Multithreading - Introduction
Python Tutorial - 26. Multithreading - Introduction
codebasics
43 Git Tutorial 3:  How To Install Git
Git Tutorial 3: How To Install Git
codebasics
44 Git Tutorial 1: What is git / What is version control system?
Git Tutorial 1: What is git / What is version control system?
codebasics
45 Git Tutorial 2 : What is Github? | github tutorial
Git Tutorial 2 : What is Github? | github tutorial
codebasics
46 Git Tutorial 4: Basic Commands: add, commit, push
Git Tutorial 4: Basic Commands: add, commit, push
codebasics
47 Git Tutorial 5: Undoing/Reverting/Resetting code changes
Git Tutorial 5: Undoing/Reverting/Resetting code changes
codebasics
48 Git Tutorial 6: Branches (Create, Merge, Delete a branch)
Git Tutorial 6: Branches (Create, Merge, Delete a branch)
codebasics
49 Git Github Tutorial 10: What is Pull Request?
Git Github Tutorial 10: What is Pull Request?
codebasics
Git Tutorial 7: What is HEAD?
Git Tutorial 7: What is HEAD?
codebasics
51 Git Tutorial 9: Diff and Merge using meld
Git Tutorial 9: Diff and Merge using meld
codebasics
52 Difference between Multiprocessing and Multithreading
Difference between Multiprocessing and Multithreading
codebasics
53 Python Tutorial - 27. Multiprocessing Introduction
Python Tutorial - 27. Multiprocessing Introduction
codebasics
54 Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
Python Tutorial - 28. Sharing Data Between Processes Using Array and Value
codebasics
55 Git Tutorial 8 - .gitignore file
Git Tutorial 8 - .gitignore file
codebasics
56 Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
Python Tutorial - 29. Sharing Data Between Processes Using Multiprocessing Queue
codebasics
57 Python Tutorial - 30. Multiprocessing Lock
Python Tutorial - 30. Multiprocessing Lock
codebasics
58 Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
Python Tutorial - 31. Multiprocessing Pool (Map Reduce)
codebasics
59 What is code?
What is code?
codebasics
60 Python unit testing - pytest introduction
Python unit testing - pytest introduction
codebasics

Related AI Lessons

Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Learn how neural geometry relies on manifolds, projections, and hidden assumptions to understand complex data, and why it matters for AI development
Medium · AI
Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Learn how neural geometry relies on manifolds, projections, and hidden assumptions to understand complex data, and why it matters for advancing AI research
Medium · Data Science
Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Explore the geometric assumptions underlying neural networks and their implications on manifold learning and projections
Medium · Deep Learning
Beyond the Elephant: On Manifolds, Projections, and the Hidden Assumptions of Neural Geometry
Learn about the hidden assumptions of neural geometry and how manifolds and projections impact neural network performance
Medium · LLM
Up next
Machine Learning Project for Final Year Students | ML Project Idea @FameWorldEducationalHub
FAME WORLD EDUCATIONAL HUB
Watch →