Skip to content

Git workflow for tutorials

Joachim Meyer edited this page Sep 6, 2019 · 2 revisions

Basic workflow to follow along with tutorials and save changes to your fork, while staying up to date with any changes made to the master tutorial.

Step 1: Creating a fork

Fork the tutorial repository via the GitHub web user interface to your account.

For example, go to: https://github.com/geohackweek/datasharing and hit the top right 'Fork' button.

Step 2: Clone the fork

Clone the forked tutorial to your machine.

In a terminal on your local environment:

$ git clone <git_url_from_your_fork>

Step 3: Configure the local repository

As a one time step to your local repository, you need to set the upstream address to fetch changes from the master tutorial.

To add the upstream address, go back to a terminal:

cd <path_to_your_repository>
$ git remote add upstream https://github.com/geohackweek/datasharing.git

The upstream parameter after add servers as a label to this repository. You could pick any name you want.

To check that it is successfully added:

$ git remote -v
origin	[email protected]:geohackweek/datasharing.wiki.git (fetch)
origin	[email protected]:geohackweek/datasharing.wiki.git (push)
upstream  https://github.com/geohackweek/datasharing.git (fetch)
upstream  https://github.com/geohackweek/datasharing.git (push)

The above example shows the origin of this repository pointing to the datasharing wiki address, while the upstream points to our URL from above.

Making changes to a forked repository

A good practice for making your own changes to someone else's forked repository is to create a branch and keep these separately.

Creating a branch:

$ git checkout -b <branch_name>  

Now you can follow along the tutorial on your fork and makes notes or change example code.

To push these changes back to your fork, do the usual commit and push:

# Making some changes
$ git add .
$ git commit  
$ git push origin <branch_name>  

Now your fork will have your changes backed up to GitHub under your branch.

Routinely updating with changes from upstream

Fetch and merge the latest changes from upstream master to your local current branch.

$ git checkout <branch_name>
$ git fetch upstream
$ git merge upstream/master