Betsy Rosalen
November 17, 2022
Git is an open-source version control system that was created by Linus Torvalds - the same person who created Linux.
|
|
|
Source: https://www.howtogeek.com/180167/htg-explains-what-is-github-and-what-do-geeks-use-it-for/
Link to this presentation: http://rpubs.com/betsyrosalen/CUNY_OAREDA_GitHub
Version control is a way of making it easier to:
Git is run in the command line (or Terminal on Mac)
| Command Prompt (Windows) | Terminal (Mac OS) |
|---|---|
|
|
|
Git is the preferred version control system of most developers, since it has multiple advantages over the other systems but it is NOT just for developers!
“the center around which all things involving Git revolve is the hub - GitHub.com - where developers store their projects and network with like minded people.”
|
|
Basically GitHub is a code hosting / GUI / Website / Community / Social Networking Site built around using Git.
You can do almost everything from the GitHub Website and the GitHub Desktop application without ever having to learn the Git command prompts.
Each user on GitHub has their own profile that acts like a resume of sorts, showing your past work and contributions to other projects via pull requests.
Project ideas and changes can be discussed publicly, so a mass of contributors can collaborate to advance a project forward.
|
|
The first two (or three) things you need to do if you want to use Git and GitHub are:
We will use the GitHub website today at first and if time allows I will show you how to do the same workflows in GitHub Desktop. If there isn’t enough time, we will do that in the next session.
A repository (usually abbreviated to “repo”) is a location where all the files for a particular project are stored. Each project has its own repo, and you can access it with a unique URL.
|
|
The ‘Repository name’ you choose when you create a repo will be part of the unique URL for your repo. So no spaces or weird characters allowed!
I recommend initializing your repo with a README file by checking the box at the bottom before you click “Create repository”.
|
|
Notice your username and the name of your repo after github.com in the URL…
To make changes click on the pencil icon to edit the file. If you have multiple files, click on the name of the file first then on the pencil…
|
|
Type your changes directly into the file on GitHub…
|
|
Then scroll down and add a summary of your changes then click “Commit changes”.
|
|
“Forking” is when you create a new project (repo) in your account that is a copy of another project (repo) that already exists in another users account so that you can work on it without changing the original repo.
|
|
|
|
Once you’ve made changes and committed them to the forked repo if you want to contribute them to the official repository you create a “pull request” asking the authors of the original repository to pull your changes into the official project.
|
|
|
|
You will have an opportunity to review your changes before submitting the request…
|
|
Put a detailed description of the changes you are asking the original repo owners to pull into their project.
Would you pull in some stranger’s changes without any explanation!?
|
|
The authors of the original repo that you forked will receive a notification in GitHub letting them know that someone (you) submitted a pull request…
|
|
They can then review your changes and your detailed commit description and merge your pull request into the main branch of the original repository…
|
|
Here’s a really quick 2 min video that shows the basic GitHub Workflow:
By default your repository has one branch named main which is considered to be the definitive branch. Use branches to experiment and make edits before committing them to main. It’s like forking your own repo.
When you create a branch off the main branch, you’re making a copy, or snapshot, of main as it was at that point in time.
I will explain branches more when we go over the Student Data Book version management example.
GitHub will throw an error called a ‘conflict’ if two people make changes to the same section of a document at roughly the same time and both try to commit and push those changes to the repo.
An easy way to avoid this is to work within separate sections separated by headers. For example set up headers in the document at the start of the project so different people can work on different sections like this…
# My Awesome Code
## Section One
One person works here...
## Section Two
Another person works here...
## Section Three
A third person works here...
The sections can be called anything you want and don’t even need to be commented out, they just need to be unchanged so that Git can recognize them in each new commit.
This is a video I made for my classmates to show them how to connect directly to my repo through GitHub Desktop so that they could push changes without sending a pull request asking for approval. In order to do that you have to make them a collaborator on your repo in the settings first, but the same steps can be used to clone your own repo to work with it on your laptop.
The big advantage to working on your laptop or desktop computer and pushing changes through Git or GitHub Desktop is that you can work in your favorite text editor so you have syntax highlighting etc. and don’t have to make all your changes directly on the GitHub website.
|
|
There are lots of tutorials and how-to videos on the internet if you just google, but here are a few especially good resources…
Use this presentation: http://rpubs.com/betsyrosalen/CUNY_OAREDA_GitHub to guide you through the following exercise…
I am here to help if you have questions!