We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Git in Control, Version Control and How it Could save Your Life

00:00

Formal Metadata

Title
Git in Control, Version Control and How it Could save Your Life
Title of Series
Part Number
35
Number of Parts
52
Author
License
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
“You can’t break GitHub, don’t worry.” Maybe you can’t break it but you can sure get yourself into a labyrinth of git commands. Version control can be a headache but it can also save your project. There are certain pitfalls to avoid when using Git, I’ve probably found most of them and stumbled my way out. While my goal is to help you avoid them altogether, I also want to give you the skills to work through these pitfalls so you can make it out alive and with your project intact. Whether you’re working on your own project, or collaborating with others you can learn how to git survive anything. We’ll discuss the benefits version control has for your own projects as well as projects with others. For all of you awesome collaborators working with others on a project, we’ll go over important steps to take while handling others’ code and ‘gitiquette’ so you can save yourself the embarrassment of faux pas in the git world. My goal is to give you an overview of Github flow, provide solutions for potential problems you may encounter, and help you feel more comfortable with version control.
Term (mathematics)Group actionComputer fileUniverse (mathematics)Forcing (mathematics)BitRevision controlDialectBit rateOperator (mathematics)WordMultiplication signTheoryDuality (mathematics)Strategy gameAlgorithmWindowRight angleSurvival analysisComputer fontLevel (video gaming)NeuroinformatikFerry CorstenObservational studyTorvalds, LinusLengthPhysical systemConfiguration spaceSinc functionNumberComputer animation
Service (economics)MathematicsDifferent (Kate Ryan album)Revision controlWeb pageUniform resource locatorTrailCodeMusical ensembleMultiplication signComputer animation
Computer fileWebsiteRepository (publishing)Point cloudNeuroinformatikInformationRadical (chemistry)CloningTheory of relativityRemote procedure callComputer animation
MathematicsComputer virusEndliche ModelltheorieSound effectLecture/Conference
Right angleComputer fileStrategy gameDisk read-and-write head1 (number)PasswordElectronic mailing listBranch (computer science)Computer animation
CodeComputer filePasswordMathematicsElectronic mailing listInformationType theoryText editorQueue (abstract data type)MultilaterationRandomizationCoordinate systemNumberPhysical lawMereologyNatural numberComputer animation
Computer fileCloningProcess (computing)OntologyLibrary (computing)NumberMixed realityCommitment schemeComputer animationLecture/Conference
Line (geometry)MathematicsMessage passingCommitment schemeDivisorLecture/ConferenceComputer animation
InformationMathematicsNeuroinformatikLecture/Conference
Video gameInstance (computer science)Multiplication signBranch (computer science)Point (geometry)Range (statistics)Different (Kate Ryan album)Moment (mathematics)Line (geometry)Office suiteComputer fileDisk read-and-write headHierarchyRight angleRevision controlReal numberNetwork topologyMathematicsSoftware developerIndependence (probability theory)Repository (publishing)Computer animation
BitProgramming paradigmBranch (computer science)Type theoryFunction (mathematics)MathematicsDifferent (Kate Ryan album)EmailComputer animation
Coefficient of determinationCASE <Informatik>Revision controlMultiplication signLine (geometry)Different (Kate Ryan album)MereologyGenderComputer fileText editorWordMathematicsBridging (networking)Wave packetLocal ringPolarization (waves)NeuroinformatikInformationSound effectInfinityOrder (biology)Greatest elementGoodness of fitCommitment schemeCodeVideo gameBranch (computer science)Repository (publishing)CloningLecture/ConferenceComputer animation
Message passingCloningStack (abstract data type)Shared memoryMultiplication signMathematicsRepository (publishing)Computer fileSoftware repositoryNeuroinformatikBranch (computer science)Right angleMereologyFerry CorstenGame theoryPoint (geometry)Network topologyHierarchyLengthPhysical lawCellular automatonStudent's t-testCountingCASE <Informatik>Statement (computer science)InternetworkingWell-formed formulaRational number
Drop (liquid)Staff (military)Electronic mailing listArithmetic meanVideo game
Presentation of a groupMereologyBranch (computer science)Video gameMessage passingNumberBetti numberMusical ensembleNeuroinformatikRankingPasswordRadical (chemistry)Electronic mailing listComputer virusSound effectComputer fileMathematicsLocal ringCommitment schemeNP-hardBlogComputer animation
Computer fileMessage passingView (database)Sampling (statistics)Computer animation
ProgrammierstilBranch (computer science)Goodness of fitCheat <Computerspiel>Data structureComputer fileMathematicsMachine visionPhysical systemClient (computing)Social classMereologyPoint (geometry)Multiplication signProduct (business)Service (economics)CASE <Informatik>Vector spaceResultantWordComputer animationLecture/Conference
Multiplication signComputer animationXML
Transcript: English(auto-generated)
This is a talk for beginners, a talk of basics. And I'll get into that in a little bit. But I'm going from all different levels of jangly get ninja-ness are welcome, so I won't judge you.
OK, let's get started. All right, so this is the basic outline so you know what we're going to be talking about. First, we'll do the who am I version control, setting up get, so basic commands. And then we'll get into the fun, tricky stuff that oftentimes tricks up people.
And then get a kit, get etiquette. All right, so before we dive in, who am I? But since I'm a little bit rebellious, I don't want to do a who am I? I want to do a get config. So get config global user name Rachel Calhoun. And yes, that's Rachel with two L's.
My mom, she likes, OK. France, Espanola, France, and university. After I graduated, I wanted to travel and learn languages. And so I combined the two.
I went to Korea to teach English for nine years. Nine years. I also studied Hangul. I studied Korean. And while I was teaching English, I thought about the future and I wanted to change careers. So I started with Python. And I found a local study group. We worked on Python. We did a lot of fun things for about a year.
Then we got into Django and we discovered Django Girls. We also made Django Girls workshop in Seoul. We have an awesome community there. And from that, I'm here. And along the way, in those two and a half years, I discovered I learned a lot of things the hard way. So I'm hoping to tell you how to do it the easy way.
Give you some emergency exits or survival strategies so you don't throw the computer out the window. All right, so now that we've done that, we're going to go to number two, version control. The importance of version control. It's good to track, record, and recall different versions
of your files. It can be code. It can be text. And even these days, we're doing a lot of art. What is Git? Git is more than 11 years old. It was created by the creator of Linux also, Linus Torvalds. I hope I said that name right. The Linux community no longer could use their revision
control system. So he created it in a weekend. If you think it's difficult after months of trying to pull your car out, he made it in a weekend, which is pretty awesome. So if you're collaborating alone, you can work. It helps with editing, reviewing, and saving different projects.
It can make it very easy. If you're on your solo project, it can help you keep track of different changes you make. It can also help if you break your code. You can go back to a different version. One other thing I like to do is it helps me work at different locations if I'm at work or if I'm at home. I can just put it on GitHub or other services
and keep continuing where I left off. And also, if you're collaborating with others, you have the same benefits, but you can also see who did what. There's git blame, which is awesome. You can also work at things at the same time.
Just a minute. So next, we're going to set up git. Before we get it set up, I want to let you know, you'll see some git commands. For people that don't know, those will be put in your black box, your command line, your terminal after the dollar sign.
And you want to make sure you're in the correct folder while you're doing that because that could cause some problems. So to git set up, first you want to make sure it's installed. If you're on Linux, it should be already. And you want to introduce yourself to git. So you'll want to do git config, global username, your name, and then your email, like this,
and replace it with your information. After that, you'll want to start. And how do we start? Git init, initiate. You can go to the folder you want to start, and you do git init. And after you initiate, you want to connect it with your online repository.
So here's your computer. And the cloud is the online repository that you want to send it to or connect it with. So you have to do git remote at origin and then put the path to origin. You can find this on the website that you created. Next, you'll want to, you can also git clone. So if there's already a project that you want to clone or copy, duplicate,
you can do git clone path to the file name. And here it's a heart. So in the cloud, that's online, a remote repository. So you'll want to do git clone path to heart, I guess in this case, right? And now you have it. And you can have fun with it.
Oops, oh my gosh, that's fast. I hope you saw that. Okay, git commands. So now we have it set up with your name. Now we're gonna go to the commands basic stuff that everyone needs to know when they're starting git. Okay, git status. And what is git status? After you're introduced, you should check it out. How are you doing, right? You want to see what's changed, what's new,
what you should do. This is also great if you don't know what you're doing because it doesn't change anything, but it makes you look like you're doing something really important, okay? So you can always do git status. And I do that sometimes if I'm, I don't know what I'm doing, okay. Hello. But it's also good for checking the repository,
see what you've added, see any changes you've made. Or if you're not sure where you're at, it'll tell you that as well. On your local, okay, git status is good at pointing out changes, okay, so let's see. This is an example. Git status, you can see where we are, we're on branch name.
And you can see the untracked file, list of passwords and passwords too. Now, if you don't know what to do with that, you can see it says, oh, it's a hit, like git add, maybe we should do that. But I don't know if you wanna add your passwords, but you can if you want to. And we'll get into that, what's adding? It's not math, but we'll see.
All right, so what is git add? After you've made some changes to your files, what you wanna do is git add. And here it's git add path to file name. So wherever your file is, you wanna let them know so they can find it. And first, you might wanna check the status to see where you're at and what files are listed to add.
And then you can see the file name, you can add it there and what adding does, it adds it to the queue, it adds it to the list, I guess you could say, of what then can be packaged, labeled and sent later. So you can see here, the heart is in a queue waiting to be packaged, okay?
Another way is git add file name, okay? So if you're currently in the same file as a file as a folder, you can do git add file name or git add heart and now it's ready to be packaged. And one last git add that I wanna talk about is git add all.
This is useful if you have a lot of things you've changed and you're ready to commit them all, but it can be dangerous because like before, if we have a list of passwords that can be added as well and not all of us want our passwords for the world to see, okay? So make sure if you, to be careful and to not add things like passwords
or to-do lists or random stuff, we can make a git ignore file and what is the git? It's .gitignore, the dot is important. And you'll want to create it on your code editor and type in the file name that you want git to ignore so it won't add it when it doesn't git add all, all right?
And so one more time, I want to emphasize, don't add important information, sensitive information to git, it can be difficult to get off. You can git it off there, but anyway, so git add all, we have heart, heart, pin, yay, heart, all right? And so it added all those and now we're ready to package it. And this is the workflow, I wanted to include this
so you can visualize the process a little better. We have git init or clone and then git add. So then what's next after we have those files in a queue? We commit, git commit. After we're ready, we commit them and it packages them all together so they're all in the package and then it labels it. Here the label is Django Girls
because Django Girls is awesome. But git actually has a really long reference ID that's a mix of letters and numbers so you can find it again later if you want to go back to that for any reason. All right, if nothing is added, nothing will be committed. You can't send and you can't package something
that doesn't exist, all right? So also one way, I'm sorry, if you do git commit, it'll open a text editor. You have to enter a message. What did you do? What are you sending? What did you change? You should let them know. If you want to do it in one line, you can do git commit dash m and your message.
Here is I made some awesome changes. Now although this is a message, a more descriptive message would be useful. What did you change? All right, so now here we are in the workflow. We initiated, we added, we committed and you can see here the commit has a label. It's C1 for commit one. Okay, and now the package is ready to go.
How do we send it? It's git push, okay? So far we've been working on our computer. After you've made a commitment, you have to follow through. So how do you get those changes on GitHub online? How do you share them with the world? Git push sends or pushes information
to the remote repository, not on your computer. And what you can do is git push origin master and that pushes the master branch. Or if you're working on a different branch, you can do git push origin branch name and that will push it from where you are
to the remote repository. So you can see here the workflow. And so next you're like, what master, what branch? Yes, we're gonna get into what is a branch? Okay, a lot of people like to talk about branches when they talk about git. So here we're going to talk about branches too.
A branch is an independent line of development. The original branch is called master by default, but off of that you can have different versions of the same file. And this is what one branch tree might look like in git. So let's say you have a big, you're at work, you have a big project you have to finish.
This is a real life example. And you wanna go to this party, but you can't do both at the same time. Well, if life was like git, you could. You could make a work branch and do your work. You can make a party branch and go have an awesome party. And then you could merge them together and be back to work. Hopefully no conflicts.
Okay, so next, let's talk about how to create branches. You can see here, there's the master branch. So how do we get, check out, okay, there. There's the work branch, sorry. So we always work before play,
so here's the work branch. It just creates it, nothing has changed. You just made another version of the same thing. All right, and then if you wanna delete it, like let's say you made a mistake, you don't wanna get fired, whatever, you can delete it by git checkout-d. Work branch. Okay, so what if you did something awesome and you want to share that work
and you wanna show it off? So here's your work branch and you made a few changes and you wanna push it to GitHub so you can do git push origin work branch. And it just pushes that branch. Okay, next, git branch is very useful. It's like git status. If you don't know what you're doing,
it makes you look like you do and it doesn't change anything. It's just checking. So this is an example of the output if you type git branch. Header changed, different branches that I had made on my project that I was working on. And which project or which branch am I currently on? Anybody know? Yep, okay. All right, let's go.
So branches, we have a little bit of understanding. Next, we're going to go to dogs. What? Anyone know what this one could be? Git fetch. Yes, very good. Although there are no dogs in git, there is fetching. All right, so what is fetch? We do git fetch origin.
Fetch is something where you collect the information that's on the remote repository. So like on GitHub, you would collect it and it's just sitting there. You didn't do anything with it yet. So if you see this, you're just copying the information from there to your computer. And then what can we do? We merge it.
And merging is what you do after fetch. It'll actually apply those changes or the updated files. And here you can see we merged the work branch to master and the party branch to master and both our work and party life are happy, right? So let's, and also don't be alarmed if git tells you there's a conflict
because sometimes, and what is a conflict? It means two lines of code are a little bit different and the same line. So you have to tell git which one do you want to keep. Okay, so let's look at that. Oh, we can see it merged. They're up there in master. All right, and a conflict.
So this, if you look in your, open your text editor and you see where the conflict is, it'll show you something like this. And you need to choose which one you want to keep, the original change or the modified change and just delete the one you don't want to add. And so after you finish, you edit it, you can then git add, git commit and push
if that's what you want to do. Okay, next. We'll go to git pull. We've done pushing, what is git pull? Git pull is git fetch and git merge in one command. You can do git pull. And what does that do? Pulls it and merges, or fetches and merges, sorry. Okay, good.
So next we'll talk about forking. If you can see the bar, unwatch star fork. There's fork, what does that do? This is the original repository and what it will do is make a copy in your online repository. We forked, okay? Now we have a heart just like them. Hopefully everyone has a heart.
Yeah, okay, so then what we want to do is we want to get it on our local computer. So how can we do that? We clone from our branch, from our online repository. And then let's see. So after creating the fork, you can git clone.
Let me see and do that again, sorry. And then, all right, so once you're feeling comfortable, you're like, okay, I got this heart, I want to make some changes. I know the basics, what do I do? So you make some awesome changes and now the heart is green. And you want to send those to the original project and you think that'll really benefit the project.
So what do you do? You can do, you git push and then once you do a git push, if you go to GitHub, there's a green button and you say compare and pull request. And now that will check the two online repositories and that's basically asking the owner of the other online repository, do you want to accept my changes?
And if they, there are three, I guess there are more, but there are three basic things that can happen. They can deny you with no comment, which is really not fun. Or they can comment with request for changes. And if they do that, what you can do is go back to your branch on your local computer, on your local repository, make the changes and send them.
You don't have to do another pull request. It'll all be in that one. It'll update while you push. Or the third thing you can do is git accepted. Yay! Good job, your green heart is now added. So I'll celebrate. And that's really how I feel when I git it.
All right, so now after you git accepted, then you should go back to something new and start again, okay? Okay. All right, so now what we want to talk about is after the fourth, you have to keep that updated. If you want to update, you can't just git pull. You have to tell your computer where is it pulling from. So you have to do a git remote add upstream,
path two, original repo. So in this case, it's the blue heart. And uh-oh, there are some changes, right? Our heart's red, our remote repository's red, and I don't want to update it. How can I do that? So then what do we do? Git pull upstream master. And now we'll update the changes. So then our heart will then be blue.
And we're up to date with the remote repository, the fourth one. All right, so let's then talk about tricky stuff. I'm gonna go a little bit fast because I see the time is ticking away. But you don't have to memorize. I'll share this later. Okay, tricky stuff.
When I first started, I felt like a labyrinth. And I would ask my friend, how do you do this on git? I don't understand. He would tell me one thing. I'd ask another friend, and she would tell me something else. I thought there was one way to do something. There's not. And then I would ask Google, and then I would ask Stack Overflow, and then I would be just lost in this labyrinth, and I've done all these crazy things and all these weird commits,
and I don't know where I am. So sometimes I just delete my local repository and start again, git clone. Or sometimes I make my way out of the labyrinth but had some iffy commit messages on GitHub. So one thing that is really awesome is git stash. Now I've been working on a branch,
and I thought I was on a different branch, but I made all these changes, and then I realized, uh-oh, I don't want these changes here, what can you do? Put those changes aside, and then go to another branch and then apply them. So that's git stash, okay? And if you do git stash, it'll stash your files but not your untracked files.
If you do git stash dash u, you will get the untracked files as well. All right, so for example, let's say you're at work, and then you get feeling like you wanna dance. Uh-oh, that's a mistake, you might get fired. So what do you do? You gotta stash those, dash those, dash those,
and then when you're at the party branch, you apply, okay? So you apply those, you apply those, okay? And that's, we'll let you example. Okay, so git stash apply, that's just applying the stash to wherever you are, and then after you apply it, you can drop it.
That's deleting it from your list of stashes. So if you're done, you can do git stash drop. One thing that will do both of these in one is git stash pop, and this is very useful. So you don't forget to delete it later, and you have a huge list of stashes. All right, and one thing I find is pretty cool
is git stash branch, like party branch or whatever branch you're on, this will do all of that. It will create a new branch and apply those stashes to this branch. So if I'm on work branch, what I can do is git stash party branch, and it will take all the changes and create party branch and apply them there.
So I don't have to worry about that. I've done this more than once. All right, so now we're going to move on to undo local commits. You made a commit and you realize you didn't want to. What do you do? Okay, so here is git reset and then two.
You can put two, you can put five. That's the number of how many commits back you want to go, okay? One example would be if you're on party branch, you have too much juice and you make some mistakes. Uh-oh, so you can git reset maybe two mistakes ago. Okay, so it will. Oh, okay.
Also you can do git reset hard head to. This is a hard reset, but be careful with hard because your modified files will not be, they will be discarded and they will be deleted. And one other thing that's useful is
specifying the commit number. I just put some random one. Don't try to find it. Git reset hard and this will go back to that specific commit. And that's why the labels are important. This will only work if you haven't pushed your changes yet, so be careful when using hard because your local changes will disappear, okay?
Let's go on to removing files. Before you saw I had a list of passwords, passwords, I added them. Uh-oh, how can I delete them? I don't want everyone to know my passwords. So you can do git rm, which remove list of passwords. But, and it deletes it from your computer as well.
So what can you do? You can remove the added files by reset. Reset is like opposite of add. It will take it off from the queue, okay? And after you've done that, you want to add it to gitignore so that you don't add it again on accident.
All right, if anyone has seen this, it's pretty entertaining for like a minute and then it's boring. Commit blogs from last night. You can see, I cover up the sensitive or the inappropriate information, but when you're tired, exhausted, in the middle of the night, or if you don't know what you're doing, you get frustrated, you can have some iffy,
some sketchy commit messages. And so how can you change those? Don't worry, you can edit, okay? And that's what I'm here to tell you about. Edit a commit message. That's git commit amend. This will open a text editor, you change your message, solved.
Or you can do git commit amend m message. That sounds like I know what I'm doing, right? But be careful because these don't change it. It makes a new commit, okay? But that can be useful too because if you forgot to add a file, what you can do is you can git add forgotten file
and then git commit amend. If you want to check what you are ready to push, this is very useful. Git diff, stat, cached, origin, master. It'll tell you what you're about to push before you make maybe a mistake.
All right, so now we've gotten through those. Let's go git, git git. What can we say about git git? When you're on GitHub, when you're collaborating, you wanna check the issues before you start a new issue. If someone's already done it or talked about it, you don't need to bring it up or it might be a result issue.
Okay, so check the history. Also, you want to name your branches descriptively so people know what you're doing. You also wanna keep your changes small. I'm very ambitious and I see a small change, one tag, one small thing, I wanna change it and then I find something else and find something else. And then I have all these changes on one branch
so you wanna make sure to keep the changes small. Just make a new branch and you can do another PR. Respect the coding style, the original coding style. Don't change the whole file just because you don't code like that. You wanna try to maintain their structure and their coding style.
And also play nice, be nice to everyone. Assume everyone is doing their best. If it's your repository, try to be helpful if you deny someone's pull request. Maybe share a resource or let them know how they can improve. If you're trying to do a pull request, in your issue, when you're making an issue,
you can be nice and assume that maybe they were busy, that's why they couldn't do something or they missed it. All right, so this, we cover a lot. I actually believe you did some, they wouldn't have been on the line, but so it's okay to be overwhelmed and this is just the start. But one thing I wanna tell you
is you don't have to feel overwhelmed. Practice and repetition and cheat sheets is the key. It may be a little bit confusing and scary from the outside, but it isn't. And you're not alone, especially with the awesome Django community. And you can always reach out for help. So I hope you can use the emergency exit that I shared with you today
and good luck on your journey. So thank you.