Useful Git Commands

This appendix describes the minimal set of git commands necessary to follow the CSLE contribution workflow (see the developer guide.).

When you start working on a new feature, first make sure that you have pulled the latest code changes by running the following commands in the root of the CSLE repository:

git checkout master
git pull origin master

Listing 184: Commands for pulling the latest code changes from the master branch.

If the above command did not succeed due to code conflicts you can either resolve the conflicts or choose to reset the code to the latest commit (this will override any local changes) by running the commands:

git reset --hard origin/master
git clean -fd

Listing 185: Commands for resetting the local version of the code to the upstream version. (Warning: this will override any local changes to the code.)

Next, create a new branch for your code changes by running the command:

git checkout -b mybranchname

Listing 186: Command for creating a new branch with name `mybranchname`.

Then you can make your code changes. When you have made a set of changes you can commit them by running the commands:

git add --all
git commit -m "comment for the commit"

Listing 187: Commands committing new code changes.

You can make several commits. When you feel that your new feature is ready to be merged into m aster you can push the code to GitHub by running the command:

git push origin mybranchname

Listing 188: Command for pushing the branch `mybranchname` to GitHub.

After pushing the changes you can go with your web browser to: https://github.com/Limmen/csle and open a new pull request.

When the pull request is merged into the master branch you can delete the local branch and pull the new changes from the master branch by running the commands:

git checkout master
git pull origin master
git branch -d mybranchname

Listing 189: Commands for (1) switching to the master branch; (2) pulling the latest changes; and (3) delete the old feature branch with name `mybranchname`.

After running the above commands you can verify that your commits are available in the master branch by running the command:

git log

Listing 190: Command for viewing git commits.