Skip to content

4. Coding guide: github (fork workflow)

Emanuel Huber edited this page Sep 18, 2019 · 1 revision

Feel free to contact me if you have any troubles, questions, comments, wishes, etc.

emanuel.huber@alumni.ethz.ch

Adapted from atlassian

Create an account

Create an account on GitHub

Initialisation

  1. Fork the 'official' server-side repository RGPR. This creates your own server-side copy

  2. Clone the new server-side copy to your local system

    git clone https://github.com/username/RGPR.git

    and move to the created "RGPR" repository

    cd RGPR
  3. Add Git remote path for the 'official' repository to the local clone

    convention:

    • origin = name of the remote for your forked repository (automatically created when you run git clone)
    • upstream = name of the remote for the official repository.

    create the upstream remote:

    git remote add upstream https://github.com/emanuelhuber/RGPR.git
  4. Check if the connection with the github works

    git remote -v

Create a new branch

  1. Before you create a new branch, make sure that:
    • you are in the master branch (i.e., the checked out branch is master)
      git checkout master
    • the master branch on your local machine is up-to-date with the official master branch
      git pull upstream master
  2. Create a new local feature branch and switch to it
    git checkout -b feature_branch_name
    Notes: -b argument is to switch directly to the created branch
  3. Push the branch on github :
    git push origin feature_branch_name
    Notes:
    • execute git branch to find out the local branches (the branch marked with an * is the checked out branch).
    • execute git branch -r to find out the remote branches.

Edit your code

  1. Make some changes

  2. Make sure you are in your branch before you commit something

    git branch

    The branch marked with an * is the checked out branch. If you are not in your branch, move to it

    git checkout <name_of_your_new_branch>
  3. Commit the changes you made:

    git add -A    # equivalent to git add --all
    git commit -m "a commit message in the present tense"
  4. Push the branch to your remote repository

    git push origin feature_branch_name

Open a pull request

One of the key points of the feature branch workflow is that the developer who wrote the code does not merge the code with master until there has been a peer review.

  1. check that your branch is up-to-date with the official branch
    git pull upstream master
  2. Push the branch to the developer's own server-side copy
    git push origin feature_branch_name
  3. Open a pull request on github (go to your branch, click on "New pull request").
  4. Your pull request will be first reviewed:

This experience also allows the peer reviewer to place a comment on any line within the update. This will be communicated back to the editor of origin. This review experience really allows for everyone on the team to be actively involved in each update.

  1. Once the reviewer has approved the editors updates, the pull request gets approved for merge and is merged into the original server-side repository Once the branch is merged, delete the obsolete branch from your local repository:
git checkout master
git branch -d feature_branch_name