Git in Control, Version Control and How it Could... by Rachell Calhoun

This video features Rachell Calhoun at DjangoCon US 2016 in Philadelphia, Pennsylvania, USA.

Git in Control, Version Control and How it Could... by Rachell Calhoun
0:26:20
Published August 12, 2016
503 views

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

“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.

This talk was presented at: https://2016.djangocon.us/schedule/presentation/22/

LINKS:
Follow DjangCon US 👇
https://twitter.com/djangocon

Follow DEFNA 👇
https://twitter.com/defnado
https://www.defna.org/

Summary

Rachell Calhoun presents Git as a way to track, review, share, and recover changes, whether working alone or with collaborators. She explains the basic workflow—configuring Git, initializing or cloning a repository, checking status, adding files, committing, and pushing—and then covers branches, fetching, merging, pulling, forks, and pull requests. She also gives practical recovery techniques such as stashing changes, resetting local commits, removing sensitive files, amending commit messages, and reviewing diffs before pushing. The talk argues that Git becomes manageable through practice, repetition, cheat sheets, and knowing a few emergency exits, while good collaboration depends on small changes, descriptive branches, respect for project conventions, and considerate communication.

Key takeaways

  • Use Git to record versions of files, recover from mistakes, work across locations, and see who changed what.
  • The basic workflow is to initialize or clone a repository, add selected files, commit them with clear messages, and push commits to a remote repository.
  • Branches support independent lines of development, while fetch, merge, pull, forks, and pull requests support collaboration and contribution to shared projects.
  • Use .gitignore to keep passwords and other sensitive or irrelevant files out of a repository, and resolve merge conflicts by choosing and committing the intended changes.
  • Git stash, reset, rm, and commit --amend provide ways to recover from misplaced changes, unwanted local commits, accidental files, and poor commit messages.
  • Effective Git collaboration involves checking existing issues, keeping branches and changes focused, following the project’s coding style, and communicating respectfully.

Summarised automatically from the transcript.

Transcript

4,603 words · auto-generated Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:00

Speaker 1: Come on, no.

0:15

Speaker 2: Alright, um well first I want to say uh welcome. There are a lot more people than I expected. Um I'm hoping I can help you get in control. Um we're gonna talk about version control and how it can save your life. And I am Rachel Calhoun. This is a talk for beginners. So we are going to talk basics and I'll get into that in a little bit. But everyone from all different levels of Um Djangoy Git Ninja Niss are welcome, so I won't judge you. Okay, let's get started. Alright, so this is a basic outline so you know what we're gonna be talking about First we'll do the who am who am I, version control, setting up git, so basic commands, and then we'll get into the fun, tricky stuff that also oftentimes tricks up people, and then git a kit, git etiquette

1:03

Speaker 2: Alright, 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 git config. So k config global username Rachel Calhoun. Okay. And yes, that's Rachel with two L's. My mom, she loves Alright, so this is my background. I studied Spanish and Francais, Espanol and France in 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 hangwa. I studied Korean.

1:48

Speaker 2: 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 and give you some emergency exits or sort survival strategies so you don't throw the computer out the window. Okay Alright, so now that we've done that, we're gonna go to number two, version control.

2:33

Speaker 2: Alright, so the importance of version control. It's good to track, record, and recall different versions of your what files. It can be code, it can be text, and even these days we're doing a lot of art What is Git? Git wa is more than 11 years old. It was created by the creator of Linux also, Linux Torvald. I hope I said that name right. The Linux community no longer could use their uh revision control system. So he created it in a weekend. If you think it's difficult after months of trying and pulling your hair 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.

3:20

Speaker 2: 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 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. All right. And also if you're on a if you're collaborating with others, you have the same benefits, but you can also see who did what. There's gig blang, which is awesome. You can also work on things at the same time Okay. For just a minute. Alright. So next we're gonna set up

4:07

Speaker 2: it. Okay, uh before we kind of 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 when to get 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 what git config global username, your name, and then your email, like this, and replace it with your information. Okay, 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 connect

4:54

Speaker 2: git In it, sorry. Um 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 get remote at origin and then put the path to origin. You can find this on the website that you created. Okay 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 and that's um in the cloud that's on 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.

5:41

Speaker 2: Oh my gosh, that's fast. I hope you saw that. Okay. Gip commands. Um So now we're gonna now we have it set up with your name, now we're gonna go to the commands basic stuff that um everyone needs to know when they're starting to get Okay, get status. And what is get 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. Um 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 a gift status and I do that sometimes if I'm I don't know what I'm doing. Okay. 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.

6:29

Speaker 2: On your local, uh okay, uh Git Status is good at pointing out changes. Okay, so let's see. This is an example. Um 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 hint, like git add. Maybe we should do that But I don't know if you want to 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. Alright, so what is git add? After you've made some changes to your files, what you'll want to do is git add. And here it's git add path to file name So, wherever your file is, you want to let them know so they can find it.

7:16

Speaker 2: And first you might want to check the status just see it you're where you're at and what files are listed to add and then you can see the file name you can add it there um 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 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 want to 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.

8:05

Speaker 2: 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 git? It's dot 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 get at all. Alright, and so one more time I want to emphasize, don't add important information, sensitive information to get can be difficulty at all You can get it off there, but anyway. So get

8:50

Speaker 2: at all. We have heart, heart, pin, yay, heart. Okay? 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 get 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. Alright,

9:36

Speaker 2: if nothing is added, nothing will be committed. You can't send and you can't package something that doesn't exist. Alright, so also one way, sorry, if you do git commit, it'll open um 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-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?

10:22

Speaker 2: It's git push. Okay. So far we've been working on our computer. After you 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 get 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

11:08

Speaker 2: master? What branch? Yes, we're going to take it into what is a branch? Okay, like 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. Okay, and you want to go to this party, but you can't do both at the same time. Well if life was like it, you could you could make a work branch and do your work. You can make a party branch and go have an awesome party.

11:54

Speaker 2: And then you could Merge together. And be back so hopefully no conflicts. Okay. And so so Next, let's talk about how to create branches, right? You can see here, there's the master branch. So how do we get check out Uh oh okay there. There's the work branch, sorry. So uh we always work before play, so here's the work branch. It just creates it. Nothing has changed. You just made it another version of the same thing. All right, and then if you want to delete it, like let's say you made a mistake, you don't want to get fired, whatever, you can delete it by get checkout D. Okay, so what if you did something awesome

12:39

Speaker 2: and you want to share that work and you want to show it off? So here's your work branch and you made a few changes and you want to push it to GitHub so you can uh do get push origin work branch and it just pushes that branch. Okay, next um get branch is very useful. Be 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 change, different branches that I had made on my project that I was Was working on. And which project or which branch am I currently on? Anyone know? Yeah, okay. Um, all right, let's go. So branches, we have a little bit of understanding. Next, we're going to go to

13:26

Speaker 2: Dogs. What? Well 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? Um we do get fetch origin. Fetch is uh something where you collect the information that's on the remote repository. 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, the master, and the party branch to master, and both our work and party life are happy, right?

14:16

Speaker 2: 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, in a conflict. So this, if you look in your uh 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 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.

15:04

Speaker 2: 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? It pulls it and merges. Or fetches and merges, sorry. Okay? Good. So next we'll talk about forking. If you can see the bar, unwatched 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

15:50

Speaker 2: from our branch from our online repository. Okay, and then let's see. So after creating the fork, you can get clone. Let me see and do that again, sorry. And then Alright, 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? Okay, 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 you say compare and pull request and now that will check the two online repositories and that what

16:36

Speaker 2: that's basically asking the owner of the other online repository, do you want to accept my changes? And if they uh 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 requests 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 get accepted. Yay! Good job. Your green heart is now added. Um so I'll celebrate. And that's really how I feel when I get it.

17:21

Speaker 2: Um, alright, so now after you get accepted then you should go back to something new and start again, right? Okay. Alright, so now what we want to talk about is after the four, you have to keep that updated. If you want to update, you can't just get 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 our remote repository is red, and I want to update it. How can I do that? So then what do we do? Get pull upstream map. And now we'll update the changes. So then our heart will then be blue. And we're up to date with the

18:06

Speaker 2: remote repository, the fourth one. Alright, 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 it felt like a labyrinth. And I would ask my friend How do you do this? I'm good. 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 made my way out of the labyrinth, but had some iffy commit messages on GitHub.

18:53

Speaker 2: So One thing that is really awesome is GitStache. Now I've been working on a branch and I thought I was on a different branch I made all these changes and then I realize, 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 then if you do get stash, it'll stash your files, but now your untracked files. If you do get stash uh dash u, you will get the untracked files as well. Alright, so for example, let's say you're at work and then you get feeling like you want to dance. Uh-oh, but that's a mistake. You might get fired. So what do you do? You gotta stash those

19:39

Speaker 2: dash mash moves. And then when you're at the party branch, you apply, okay? And that's uh real example. Okay, so

19:52

Speaker 3: uh

19:52

Speaker 2: so we have git stash applied. 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 uh 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 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 get stash party branch and it will take all the changes and apply

20:38

Speaker 2: create party branch and apply them there. So I don't have to worry about that. I've done this more than once. Alright. So now we're going to move on to un uh to undo local commits. Um you made a commit and you realize you didn't want to. What do you do? Okay, so here is git reset and 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, um 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 get reset, uh maybe two mistakes Okay, so it will

21:21

Speaker 3: show

21:22

Speaker 2: Okay. Uh also you can do git reset hard Head to this is a hard reset, but be careful with hard because your um modified files will not be s they will be discarded, they'll be deleted. Um and one other thing that's useful is Specifying the commit number. I just put some random one. Don't try to find it. Get 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 harm because your local changes will disappear Okay. Um let's go on to removing files. Before you saw I had a list of passwords. Passwords I added them.

22:07

Speaker 2: 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 uh oh, try that 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 on, it will take it off from the queue. Okay? And after you've done that, you want to add it to git ignore so that you don't add it again on accident. Alright. If anyone has seen this, it's pretty entertaining for like a minute and then it's boring. So um commit blogs from last night. You can see I cover up the sensitive or the inappropriate information, but um when you're tired, exhausted in the middle of the night

22:56

Speaker 2: Or if you don't know what you're doing, you get frustrated, you can have some iffy, some sketchy commit uh messages. And so how can we change those? Don't worry. You can edit, okay? And that's what I'll hear to tell you about. Edit a commit message. That's git commit amend. This will open the text editor, you change your message. Solved. Or you can do git commit amandm message that sounds like I know what I'm doing, right? And but um 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

23:42

Speaker 2: Get commit amend and you're safe. And if you want to check what you are ready to push, this is very useful Git diff stat hash origin master. It'll tell you what you're about to push before you make maybe a mistake. Alright, so now we've gotten through those. Let's go to get Git a kit. What can we say about Gitakit? When you're on GitHub, when you're collaborating, you want to 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 an unresolved issue. Okay, so check the history. Also, you want to name your branches descriptively so people know what you're doing. You also want to keep your changes small.

24:30

Speaker 2: I'm very ambitious and I see a small change, one tag, one small thing, I want to change it, and then I find something else, and find something else. And then I have all these changes on one. uh branch so you want to 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 want to try to maintain their 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.

25:15

Speaker 2: If you're trying to do a pull request Don't in your issue when you're making an issue you can be nice and assume that maybe you know they were busy, that's why they couldn't do something or they missed it. Alright, but so this we cover a lot. I actually did leave some they wouldn't film the lines but um so it's okay to be overwhelmed and this is just the start so um but one thing I want to tell you is you don't have to feel overwhelmed practice and repetition and cheat sheets um is the key It may be look a bit confusing and scary from the outside, but it isn't, and you're not alone, especially with the awesome Daniel community, and you can always reach out for help. So I hope you can use the emergency exits that I shared with you today

26:00

Speaker 2: and good luck on your journey. So thank you.

Questions this talk answers

What is Git useful for?

Git tracks, records, and recalls different versions of files. It lets you review changes, recover an earlier version after breaking code, work from different locations, and see who changed what when collaborating.

Discussed at 2:33

How do I set up a Git repository and connect it to a remote?

Configure your name and email with `git config`, initialize a local repository with `git init`, and connect it to an online repository with `git remote add origin`. If the project already exists remotely, use `git clone` instead.

Discussed at 4:07

What is the basic Git add, commit, and push workflow?

Use `git add` to put changed files into the staging queue, `git commit` to package and label them with a message, and `git push` to send the commits to the remote repository. You can push the default branch with `git push origin master` or specify another branch.

Discussed at 8:50

What is a Git branch and why use one?

A branch is an independent line of development, allowing different versions of a project to be worked on separately before merging them. You can create a branch with `git checkout -b`, push it with `git push origin branch-name`, and remove it with `git checkout -d` when it is no longer needed.

Discussed at 11:08

What is the difference between git fetch, git merge, and git pull?

`git fetch origin` copies information from the remote repository without applying it, while `git merge` applies those changes to your current branch. `git pull` combines fetching and merging in one command.

Discussed at 13:26

How do I resolve a Git merge conflict?

Open the conflicted file, choose whether to keep the original or modified version, and delete the unwanted conflict markers and content. Then run `git add`, `git commit`, and push the result if appropriate.

Discussed at 14:16

How do I contribute changes to someone else's GitHub project?

Fork the project on GitHub, clone your fork locally, make changes, and push your branch. Then open a compare and pull request so the original project's owner can accept the changes or request revisions.

Discussed at 15:50

How can I temporarily set aside Git changes and apply them on another branch?

Use `git stash` to put your current changes aside, adding `-u` if untracked files should be included. On the intended branch, use `git stash apply`, or use `git stash pop` to apply and remove the stash at the same time; `git stash branch` can create a branch and apply the stash there.

Discussed at 18:53

How do I undo local Git commits?

Use `git reset` followed by the number of commits to move back, or specify a commit identifier. `git reset --hard` also discards modified files, so it should be used carefully and only for changes that have not been pushed.

Discussed at 20:38

How do I remove a sensitive file from Git and stop it being added again?

Use `git reset` to remove the file from the staging queue, then add its filename to `.gitignore` so it will not be staged accidentally in the future. The talk specifically warns against adding passwords or other sensitive information.

Discussed at 22:07

How do I change the last Git commit message or add a forgotten file?

Use `git commit --amend` to edit the previous commit message. If you forgot a file, stage it first with `git add`, then amend the commit so the file is included.

Discussed at 22:56

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos by Rachell Calhoun

More videos from DjangoCon US