Skip to content
Snippets Groups Projects
Forked from R3 / school / courses
1166 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Branches

Branch-off within the same repository in order to stay safe!



The master branch

One branch per feature

Assume that you want to work on a function for a matrix-vector operation.

$ git checkout -b matrix_vect_mult_myName
# creates the branch locally

The -b flag creates the branch.

Push the branch to the remote repository

$ git push

If you do that, git might complain

fatal: The current branch matrix_vect_mult_myName has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin matrix_vect_mult_myName

Follow the advice and do ```bash $ git push --set-upstream origin matrix_vect_mult_myName ```

Switch between branches

In your terminal, you may see the name of the branch you are on.

List available branches of the repository

$ git branch --list

Checkout another branch ```bash $ git checkout ```

You can switch back to the `master` branch with ```bash $ git checkout master ```
You can use the 5 essential commands as before.

Only difference: you are on your own branch.

Merge a branch

If you want your feature on the develop or master branches, submit a MR or a PR via the Github/Gitlab interface.


Use the **interface** to make use of your peers to review your code!
Once merged, you can delete the branch via the interface.

Gitlab interface

GitLab

Detailed information is docs.gitlab.com/ce/gitlab-basics/add-merge-request.html.

  1. Click on New merge request

New Merge Request

2. Compare the branches

Compare branches

  1. Submit the MR

    Submit MR

Github interface

GitHub

Detailed information is help.github.com/articles/creating-a-pull-request/.

  1. Click on New pull request

New pull request

2. Compare the branches

Compare branches

  1. Submit the PR

    Submit MR