(Brief) Introduction to Git + GitHub


Preface:

Version control is a system that manages changes to a file or files. These changes are kept as logs in a history, with detailed information on what file(s) was changed, what was changed within the file, who changed it, and a message on why the change was made. This is extremely useful, especially when working in teams or for yourself 6 months in the future (because you will forget things)!

To understand how incredibly powerful version control is, think about these questions: How many files of different versions of a manuscript or thesis do you have laying around after getting feedback from your supervisor or co-authors? Have you ever wanted to experiment with your code or your manuscript and need to make a new file so that the original is not touched? Have you ever deleted something and wish you hadn’t? Have you ever forgotten what you were doing on a project? All these problems are fixed by using version control (git)!

We are going to go over a typical workflow. This could be either a solo workflow or a collaborative workflow.

Checklist:

(If we have time):

Tips:

Lesson topics and commands

For configuring your git, follow the “Initial setup” I’ve put together:

Create a folder and create a git repository (which is the stored history) in that folder. (Note: ## is a comment, not a command).

cd ~/Desktop ## Move to your desktop
mkdir playing ## Create a folder (aka directory)
cd playing
git init ## Create the repository (init = initialize)

Now, create a file, get git to track it, and save it to the history.

touch bio.txt ## Command to create a file called bio.txt
ls ## Check that you created the file, ls = list files
git add bio.txt ## Track the file
## Save the file to the history with a message (-m)
git commit -m "Initial commit"

Now, open the bio.txt file and add:

Then:

git status ## Check the activity
git diff bio.txt ## Compare to the one in the history
git add bio.txt ## This sends it to the staging area
git commit -m "Added my bio" ## This sends it to the history

For a description on what the different stages are (working directory, staging area, and committed history) see the below links:

Then, to see what has happened in your history:

git log ## View the log of your history

If we have time, we’ll create a GitHub account, create a GitHub repository (a remote repository), and upload the repository on your computer (called the local repository) onto the remote repository (GitHub):

git remote add origin https://github.com/yourusername/playing.git
git push origin master
git pull

Now you know about a typical workflow! There are lots of commands and options in git, you really can do almost anything. However, these are the basic tools that are used most frequently. If you have any questions, please check out StackOverflow for literally any question on or about Git!! Or just google it! Google usually shows answers from StackOverflow.

Resources:

Glossary:

Here are a few great resources (excluding StackOverflow) to use if you ever need help: