Introduction to Git and GitHub

Git Introduction

Git (/ɡɪt/) is a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.

– Wikipedia

Git is an open source program for tracking changes in text files.

– GitHub (https://help.github.com/articles/github-glossary/)

What is Git?

Keeping track of file versions is hard.

So what is Git, and why does it help us?

Above all else, Git is a fast and distributed version control system that allows you to efficiently handle projects large and small.

Here are some problems we face as developers, and how Git solves them:

Reverting to Past Save Points (Commits)

Git allows us to make save points at any time. These save points are called “commits.” Once a save point is made, it’s permanent and allows us to go back to that save point at any time. From there, we can see what the code looked like at that point or even start building off that version.

Keeping Track of What Each Save Point “Meant” (Commit Messages)

Every commit has a description (commit message), which allows us to describe what changes were made between the current and previous commit. This is usually a description of what features were added or what bugs were fixed.

Additionally, Git supports tagging, which allows us to mark a specific commit as a specific version of our code (e.g., “2.4.5”).

Comparing Changes to Past Save Points (Diff)

It’s often important to see the content of the actual changes that were made. This can be useful when:

  • Tracking down when and how a bug was introduced
  • Understanding the changes a team member made so you can stay up-to-date with progress
  • Reviewing code as a team for correctness or quality/style

Git allows us to easily see these changes (called a diff) for any given commit.

Non-Linear Workflow (Branches)

Git enables you to work using a non-linear workflow. This means that you can have multiple versions of a project or “branches” with different save points, or “commits,” simultaneously within the same folder and easily toggle between them. You can split new branches off a project when you’re looking to experiment or implement a new feature, and you can merge those branches back into the main (formerly known as “master”) branch when you’re ready to incorporate them into a project.

Fearlessness in Making Changes

In developing software, we often want to experiment in adding a feature or refactoring (rewriting) existing code. Because Git makes it easy to go back to a known good state, we can experiment without worrying that we’ll be unable to undo the experimental work.

Git Versus GitHub

  • Git is a distributed version control system. It is a technology.

  • GitHub is a social coding platform where Git repositories are stored and where people can collaborate on projects. GitHub is great both for collaboration within your organization, but also provides an excellent model for open source collaboration across organizations or with the public.

  • On GitHub you can find Git repositories.

Learn More: https://jahya.net/blog/git-vs-github/

Some Vocabulary

The basics:

  • Git: Version control software
  • Repository: A folder containing your files and also containing a structure that helps keep track of changes in those files. When you initialize a repository, Git creates a hidden folder (.git folder) that stores the changes to those files.
  • Commit: The basic unit of a Git repository is a commit. It is a set of changes to a file. A commit usually comes with an ID as well as a commit message that describes the change.

Working with others:

  • GitHub: A place to host Git repositories and collaborate
  • Local Repository: The version of a Git repository on your local computer
  • Remote Repository: The version of a Git repository stored somewhere else that your local repository is connected to (frequently on GitHub)

GitHub Introduction

GitHub is a place for:

  1. Storing and viewing your Git repositories
  2. Collaborating on coding projects within an organization
  3. Open Source Collaboration: People in other organizations or complete strangers can see your code and participate with you on your project. They can suggest fixes, point out errors, and start discussions. You can find other people’s work and make sure you’re not duplicating something that already exists. Or you can interact with someone who has already worked on something similar to what you’re trying to tackle.
  4. Web Hosting: The “GitHub Pages” feature allows you to host a static website for free, right on GitHub.

Other Uses

  • A place to store code
  • A place to store data
  • A place for discussion about data and code
  • A place for open source collaboration on projects
  • A place for collaboration within an organization
  • A place to find people working on the same things you are
  • A place to find sources/people with expertise in a particular dataset
  • A place to find other digital tools (scrapers, file converters, etc.)
  • A place to find open source work and analysis
  • A portfolio of your technical work (or technical learning)

Let’s Dive In!

Vocabulary:

  • Local Repository: A folder stored on your computer
  • Remote Repository: A folder stored on GitHub

Let’s take a look at a repository that is on GitHub:

(Some of) GitHub’s Features

The README.md File

GitHub looks for a “README” file and renders it as you’re navigating through the file structure. This is a great way to guide people through your code.

README files are often given the .md extension, meaning they’re written in a language called Markdown that allows for nicer formatting. You can check out this Markdown cheat sheet if you want to see how formatting works, but you can also save a README file as plain text. GitHub will also detect .txt files, or you can just write plain text inside your .md file.

Commit Log

Vocabulary:

  • Commit: The basic unit of a Git repository is a commit. It is a set of changes to a file. A commit usually comes with a commit ID as well as a commit message that describes the change.
  • Commit Log (aka Git History): All of the commits (previous changes) to all of the files in your repository

https://github.com/dmil/my-simple-website/commits/master

History, Raw, and Blame for Any File

Branches

Pull Requests

Proposing Edits

You can edit a file in GitHub in a new branch, thus proposing a change without actually making the change in the main branch. Just make sure to leave a meaningful description of the change you made in the commit message.

Drag and Drop

Collaboration

Collaborators can push to the repository without asking your permission; they have full read and write access.

If I wasn’t a collaborator, I could still work with you on an open source project through a process called forking, where I can make a copy of your repository in my GitHub account, make changes, and request that you merge them back into your project. We will discuss forking more in-depth later.

Serving Up Websites!

GitHub is also great for serving up static websites. GitHub is only storing the code. Luckily, if your code happens to be a website, GitHub can also host it for you through a feature called “GitHub Pages.”

Simply go to the “Settings” menu, scroll down to “GitHub Pages,” and select “main branch.”

Whatever is in your main branch on GitHub should now appear at: