GitHub forks and pull requests

Date 02/09/2014

Git client should be configured with your GitHub account information, so that the commits are registered to your user account at GitHub, instead of the current computer. Example commands below, please substitute with your proper values:

git config --global user.name "Juga Paazmaya"
git config --global user.email paazmaya@yahoo.com
git config --global github.user paazmaya

In case you wish to make the above configuration changes to a given repository, omit the --global parameter.

Tasks that are done during this lecture:

  1. Create local repository, git init

    • Add files to it, git add

    • Commit those files with a meaningful message, git commit -m

  2. Create an empty repository at GitHub

    • Add that as a remote for the repository made in task 1.

    • Push your local repository to GitHub, making it public, git push

  3. Create new repository at GitHub, with predefined files

    • Clone the repository, git clone

    • Make changes and push them

  4. Tag the latest commit of the repository made in 3. with Semantic Versioning number, git tag

    • Add release notes to it in GitHub, thus making it a release

  5. Create a fork from a repository of the student sitting next to you, that was created in 3.

    • Make few changes to the README.md and push

    • Create a Pull Request

  6. Make changes to your own repository, which the other has forked

  7. Update the fork created in 5., git fetch, git merge

Now that you are familiar with Git, GitHub and forking, feel free to fork this repository and create a pull request that would add your presentation subject and date #11.

Examples for the tasks

1. Local repository with a file and a commit

mkdir first-git-project # create directory
cd first-git-project # go to the directory
git init # initialise a local git repository
touch README.md # create empty file
git add README.md # add a file under version control
git commit -m "First file created" README.md # commit the file

2. Create empty repository at GitHub and push to it

After creating the empty repository via GitHub web page, add it as a remote and push to it.

git remote add origin git@github.com:paazmaya/modern-web-tools-with-node-js-book.git
git push -u origin master

Please note that the -u parameter is a short version of --set-upstream which is seen in the documentation. It needs to be used only at the first time pushing, after setting the remote repository URL.

3. Repository with predefined files

After creating the repository via GitHub web page, and selecting a predefined Node specific .gitignore file, license and default README, clone it to your computer.

git clone git@github.com:paazmaya/modern-web-tools-with-node-js-book.git
cd modern-web-tools-with-node-js-book # go to the directory
nano README.md # open the file in an editor
git commit -m "Updated description" README.md # commit the changed file
git push # make the changes public

4. Tagging

git tag v0.1.0 -m "Time to make the first release with basic functionality"
git push --tags

Now in the release page at GitHub repository, the release needs to be created.

5. Forking

git clone git@github.com:paazmaya/modern-web-tools-with-node-js-book.git
cd modern-web-tools-with-node-js-book # go to the directory
nano README.md # open the file in an editor
git commit -m "Updated description" README.md # commit the changed file
git push # make the changes public

The rest of the task needs to be done in the GitHub page of the fork repository, where exists buttons for compare and pull request.

7. Updating fork

Assuming that the current working directory is the fork and it has master checked out:

git remote add upstream git@github.com:paazmaya/modern-web-tools-with-node-js-book.git
git fetch upstream master
git merge upstream/master
git push

Last updated