GitHub¶
Aims / Outcomes / Expectations:
Provide an overview of
GitHub
andgit
Demo:
GitHub
and features recommended for this workshopProvide resources for interested participants
What is GitHub?¶
It is a website that hosts Git projects and adds an interface for:
tracking issues,
reduce complexity of code reviews, and
simplifies collaboration on projects
enables web integrations (i.e. automated workflows)
GitHub consists of users
(individuals) and organisations
for
grouping projects in an organisation setting such as QuantEcon
Here are the 2020 year in review statistics
There is a useful training guide that is
put together by the GitHub
team.
Another access option is to use Github Desktop but I find the website to be
my preferred access option coupled with terminal based workflows with git
.
Tip
If you are solely interested in LaTeX projects there are other services available that offer collaboration features such as overleaf but requires a paid account.
What is Git?¶
Git is a distributed version control
system that sits on top of
your file system that tracks the state of a collection of files.
Its major strength is text type data (manuscripts, code etc.) but can keep track of other file types also.
It can help you determine exactly what has changed, why it has changed, and who has changed it.
Key Concepts of Git¶
Working Directory
Staging Area
Local Repository (Repo)
Remote Repository (Repo)
as git
is distributed
the local and remote
repositories have access to the same history information.
Git Workflow¶
A file in a Working Directory can have one of the following three states
Modified changes detected
Staged changes are marked to be committed
Commited changes stored in local repository
Note
You can find the status of files using:
git status
Setting up Git¶
When using Git for the first time it can be a good idea to setup Git with the correct user information.
Open a terminal (or Git Bash (Windows)):
$ git config --global user.name "Your name here"
$ git config --global user.email "your_email@example.com"
Note
You can check the configuration using:
git config --list
Setting up a Repository (GitHub)¶
Go to GitHub (in browser) and click on New
Cloning your Repository¶
To get a copy of the repository on your local machine
Open a terminal
:
cd <working-directory>
git clone https://github.com/<username>/<repo-name>.git
Fetching the latest from GitHub¶
If you already have a local copy of the repository on your local computer then you should always fetch the latest changes before starting your work.
Open a terminal:
git pull
this is particularly the case in collaborative environments.
Adding a Change¶
Navigate to the repository via terminal
Create a file such as first.txt
and use:
git status
to check on git
state
Committing a Change (Local)¶
We will want to move the file first.txt
into the staging area
in preparation for committing.
In Terminal
:
git add first.txt
Once we have added the files we want to commit them to history
In Terminal
:
git commit -m "initial commit"
Pushing a Change (GitHub)¶
To get those changes on your remote GitHub copy of the repository we need to push them to GitHub:
In Terminal
:
git push origin master
Viewing results on GitHub¶
(Optional) Git - Advanced¶
Git has a lot of features:
we will run through branching
Branching¶
A branch is like a parallel copy of the master/main branch.
It allows changes to occur in parallel.
The master/main branch does not get modified until the branch is merged into the main** branch.
Using GitHub this is called a pull request
.
Setting up a Branch:
Let’s setup a branch
git checkout -b first-branch
and then add a file second.txt
and/or modify first.txt
Adding a Change:
We now want to follow the same commit workflow as before
git add second.txt
git commit -m "adding a second file"
Pushing the Change:
Pushing this branch to GitHub’s copy of the test repo
git push origin first-branch
Setup a PR on GitHub:
Look for:
then setup a PR
by clicking on Compare and pull request
Suggested Workflows¶
Key GIT Commands¶
The vast majority of interactions with git is focused on these commands
git status
git pull
git checkout -b <branch-name>
git add
git commit -m "message"
git push
A Common Terminal Workflow¶
git pull
: retrieve new updatesgit status
: show status of commitGeneral work and edits
git status
: show status of commitgit add .
: puts all changed files into staging areagit commit -m "some message"
: commit changes to local git repository with a descriptiongit push
: pushes the new version to Github
Further Reading / Resources¶
Git Resources¶
Understanding Git:
GUI Options (OS X and Windows):¶
Some like to start by using a GUI
I typically recommend terminal based workflows
Exercise¶
(Exercise 1: Clone Workshop Repository)
Clone the workshop repository:
git clone https://github.com/QuantEcon/2021-workshop-rsit.git