Intro To Git

What? Why? How?

"Inspired" by

Noah `strum355` Santschi‑Cooney's slides

inspired by Colm `mloc` ó hIcí's slides inspired by Adam Gillessen's slides

What is Git?

Created by Linus Torvalds in 2005


Git is a system in which developers can track changes in files in a timeline and can merge timelines to incorporate other developer's changes into their own timelines

Why use Git?

  • Have you ever made a mistake that you couldn't fix it Ctrl+Z
  • You're sick of collaborating code over Google Docs?
  • Version Control is heavily used in companies for code versioning and collaboration.

How does Git Work?

Code is stored in Git as a collection called a repository.

Changes are represented by commits, which have an owner, message and set of changed files.

How to use Git?

The default way is through the command line

There are a number of GUI tools built around the Git ecosystem and many editors have Git support built in

Cloning

Downloads a copy of a remote repository including all history to your computer.

						
							# Clone the repo
							$ git clone https://github.com/UCCNetsoc/hacktoberfest.git
						
					

If you are working with GitHub you may want to clone your fork instead

						
							$ git clone https://github.com/jac/hacktoberfest.git
						
					

Making Changes

Now that the repo is cloned, you can do whatever you want to the local files. Once we make some changes we can use `git status` to see what files have changed:

						
							$ git status
							On branch master
							Untracked files:
							(use "git add ..." to include in what will be committed)

							sample.txt
						
					

`git status` will show you any files that have been added, changed, or removed

Making Changes

We can now use `git add` to choose the files we want to include in the commit

						
							$ git add sample.txt
						
					

And then we use `git commit` to actually record the commit:

					
						# allows setting the commit message in the quotes
						$ git commit -m "big big ch-anges"
					
					

And finally, `git push` to upload the changes to the remote repository (GitHub, in this case)

Hold on! GitHub? Forks?

GitHub is a more easily accessible interface and user experience for collaborating

Users can "fork" repositories, creating a copy/snapshot of a repository under the user's account

After making changes to this fork, users can create a "pull request" to request the changes be "pulled" into the main repository

Fork & Pull Request demo!

Reviewing

If you're maintaining an open source project, 80%+ of your time will be spent reviewing other people's code

GitHub makes this relatively easy with pull requests

Reviewing a pull request demo!

Questions?

Thanks for listening!

More reading: