Git Tutorial 6: Branches (Create, Merge, Delete a branch)
Skills:
Tool Use & Function Calling70%
Key Takeaways
This video tutorial covers the basics of Git branches, including creating, merging, and deleting branches, to manage alternate versions of code.
Full Transcript
dear friends in this tutorial we are going to look at branches in gate let's first see why branches are needed if you have code like this where I have this file hungry dot py and let's say you are making some crazy changes on this file ok and these changes are experimental in nature so that you might throw them away hence you want to preserve your original code so in order to do that what you'll typically do is you will copy/paste this file ok and then you will make your changes here I will just call it original file so this one is my original file original file and then you will make your changes here bunch of changes here and then you run it and you kind of do your experiment with it that way your code is still saved in this original file ok but this way of working is not very efficient so get by default supports this branch concept which essentially allows you to do the same thing it allows you to create two branches of your code where you can do parallel code development on both the branches you can make experiments you can test stuff and once things look ok you can merge them back into one file ok so that's essentially what primes will do for you now if you noticed or whenever you have good directory you will see master here so master is a default branch that it will give you now I want to make experimental changes on this core so I need to create a new branch so first let's run git branch come on when you do that it will list all the branches that you have I only have master right now I am going to create a new branch called thirsty and when I do get branch I now see master and thirsty okay now first you need to make thirsty branch active you see there is a star here and this is in green color which means master is an active branch so to make thirsty branch active you will run git checkout spaced branch named thirsty now it is saying it switched to branch thirsty so now you are on a thirsty branch again when you run git branch you'll see star in front of thirsty okay I will now make my changes so if you are not hungry I want to ask are you thirsty so I will just say input odd I you thirsty and based on the user feedback are the asked user to drink water okay so let's say this is your code you ran it it works fine so now you want to commit it so you say git commit before doing it commit you always need to do you get ad and then you get commit minus M water okay so you committed your change into thirsty branch okay now let's so let's check out our master branch back and let's see what our master branch has so I just checked out my master branch and when I move my cursor here you notice that all those changes went away because master branch doesn't have those changes those changes are experimental in nature and they exist only in thirsty branch okay so masters Magda brands now if I again go back to thirsty I will be able to see those changes so you notice there is no thirsty change when I when I switch the branch I will now see this changes right so it's quite powerful all right now let me make one more change so I added water now I am going to ask my kid to drink soda as well because it's so thirsty right so I added that and I will now commit this change as well cool so now if you do get long you see soda water per groupies are all the previous changes and if you switch the branch to master you will obviously lose those changes and when you do when you do get long okay I mistakenly tired let me type it here good long I see only border Pisa you see I don't see any water and soda changes because I am on master branch and that branch doesn't have any or thirsty related for changes okay so I will keep on making my core changes in my thirsty branch like this execute the code run it and the moment when I feel that these chord changes are ready to merge I will do the mush but before I show you the marsh let me now make a chord change into master branch so if you want to make a chord change in master branch you need to check out master branch so now I'm in master branch Here I am going to add so I love to eat junk food so I'm not going to eat only samosa but pizza burger and fries as well okay and as usual you do get a git commit to add your fries we need to get log you have fries burger peas etcetera but this change eat fries doesn't exist in you're thirsty branch you can always verify by checking it out so you see there is no fries here okay so just to give you kind of pictorial view of what we just did you can take a look at this picture so we we're on master branch this this line here is our master branch and we all the circles are individual commits so you added Pisa you added burger and at this point you created a new branch called thirsty so all green colored dots are commits into thirsty branch okay so you added water juice here you are the fries here so fries is not present in thirsty branch and water in juice is not present in master branch okay so now what we are going to do is these changes look okay and I want to merge a thirsty chord changes into master in order to do that you first need to go to your base branch where you want to merge into so I want to merge thirsty chord changes into master branch hence I am going into master branch master branch first okay so master is my active branch and now I will do git merge thirsty this is that moist thirsty branch into master branch when you do that it will ask you to type in the commit message I will do : WQ that will save my commit message and my Maj is done so when I cat get log here here after fries I have one more change which says Kate branch Marge branch thirsty alright now when I look at the code here you will notice now it is a merger of these two branches I have my thirsty code as well and I have fries as well so this is explained by this picture here so until this point you were two different branches and now you merged so at this point you have fries and water and juice as well okay alright now when I look at my github repository I only have master here because I have not pushed my changes so this is the place where you see all the branches on github okay I'm going to now push the thirsty branch okay so it says good push alright so it is not alright so you will just do git push and this is failed to push reference up to the DJ because it is behind integrator remote changes okay let me do get poked is something which is not okay git push now when you do get push it's gonna post the master branch alright so right now what it did is when you do get push at any time it is just pushing the current active branch so master changes are pushed if I look at here I see all the all the changes say fries and thirsty and everything okay but now I want to help thirsty branch present here as well so for that you need to check out that branch first so now your interests around and now you do git push okay what this is saying is that upstream meaning github doesn't help thirsty branch so you want to push a new branch use this command yes I want to do that so just copy paste this command and what this is saying is set upstream origin thirsty meaning pushed thirsty to my upstream which is github so now when i refresh and take a look here I have two branches master and thirsty so when I switch the branch here thirsty look at my core this is just my thirsty branch code it doesn't have fries here and if you look at master it has everything okay so branches essentially allows you to maintain two separate copies of your code okay and those copies might have alternate versions of your code your algorithm or whatever you're trying to do all right okay now let's see how you can delete the branch okay so I'm going to show you how to delete the branch so for deleting the branch first let me create some dummy branch now last time when we created a branch we shoot two commands get branch and then get checkout you can do both the things in one come on by doing it check out - be dummy so mine what this is saying is create a new branch called dummy for me - B means branch and also check out that branch alright so now it created the me branch and it made that active as well so if you do get branch see you see a third branch called dummy and this is active ok now what I'm going to do is delete this branch so get Ranchos three branches I want to delete the me the way you do it is by running git branch - dee dee means delete dummy when you do that it says it deleted the brunt so now when I do get branch I don't have that planche anymore alright so that was all about get branches and great merging thank you for
Original Description
In this tutorial, I'll cover a very powerful feature of git called branch. I will show you how you can manage alternate versions of your code by creating separate branches, how to merge branches and delete them. Here is the list of topics covered in this git tutorial,
1) how to create a new branch in git
2) merging a branch
3) deleting a branch from local as well as remote
Git Tutorial: https://www.youtube.com/watch?v=xAAmje1H9YM&list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW
Do you want to learn technology from me? Check https://codebasics.io/ for my affordable video courses.
Next Video:
Git Tutorial 7: What is HEAD?: https://www.youtube.com/watch?v=ZaI1co-rt9I&list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW&index=7
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
Playlist
Uploads from codebasics · codebasics · 48 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
▶
49
50
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
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
Slack Built Its Own EC2 Platform. Buying One Was the Harder Question.
Medium · DevOps
Engineering Culture Starts with Version Control — Building Trust, Ownership, and Collaboration at…
Medium · DevOps
Not Every Workload Belongs on a Free Server: Red Flags and Exit Criteria
Dev.to · Casey Sun
Reviewing a PR You Can't Run Locally: A Reproducible Free-Tier Loop
Dev.to · Blake Yang
🎓
Tutor Explanation
DeepCamp AI