|
|
On this page we will describe how to use Git to update your local files, make new branches and push changes to the remote repository. We assume that you have cloned the OpenSimRoot repository and have added the remote repository under the name "origin". See https://gitlab.com/rootmodels/OpenSimRoot/wikis/get-started-via-the-terminal-on-linux if you're unsure if this is the case.
|
|
|
|
|
|
Git keeps track of all the changes that are made to code and provides useful tools that allow multiple people to work on the same project simultaneously. This is usually done using branches. The main version of the code is called the master branch. Think of each other branch as a copy of the code that differs slightly from the code in the master branch. Usually someone will work on a branch until the code is satisfactory and then send a merge request. Then the changes will be reviewed and, if appropriate, merged with the main branch. It is also possible to work in a different 'fork'. Different forks act more like separate copies of the project, while branches are part of the original project. For more, see: http://stackoverflow.com/a/13403195
|
|
|
|
|
|
Before we start, a useful command is: `git status`. With this command git will tell us on which branch we are and if there are any changes we have made that have not been staged for commit yet.
|
|
|
|
|
|
First we should ensure that our code is up-to-date. Enter git pull origin. You might see the following error message:
|
|
|
|
|
|
```
|
|
|
You asked to pull from the remote 'origin', but did not specify
|
|
|
a branch. Because this is not the default configured remote
|
|
|
for your current branch, you must specify a branch on the command line.
|
|
|
```
|
|
|
|
|
|
This means you have not specified a default branch for your current branch. You can do this by entering `git branch --set-upstream-to origin/master`. This will set the master branch of the remote repository (assuming you called it origin) as the default branch for your current branch (which should be your master branch). Now you can use `git push` and `git pull` without specifying the branch. To see what has been changed, use `git diff master@{1} master` (you can enter higher values instead of 1 to look farther back).
|
|
|
|
|
|
To make a new branch, use the command: `git branch nameofnewbranch`. To change to a different branch, you use `git checkout nameofbranch`. These can also be combined into one command as `git checkout -b nameofnewbranch`. **Important! Do not make a branch with the same name that already exists in the remote repository to avoid issues.** So suppose we want to make a new branch called examplebranch, we enter `git checkout -b examplebranch`.
|
|
|
|
|
|
Suppose we made some changes to a document called `example.txt` in our new branch. If we enter git status, git will tell us that this file has been changed but has not been staged for commit yet. We will have to add this file to the commit.
|
|
|
|
|
|
To add the file to the commit, enter: `git add example.txt` and check if it has been added by using `git status`. It is possible to see what has been changed with `git diff HEAD`.
|
|
|
|
|
|
|
|
|
To actually commit the changes, use `git commit -m "A message explaining what you changed."` You can edit various entries using `git commit --amend`. If we are satisfied with our changes we can push our changes to the remote repository with `git push origin examplebranch`. You should now be prompted to enter your SSL key (if you set one). After entering this your changes should be pushed to the remote repository, making them available to all (provided you have the necessary permissions). See below for a comprehensive example showcasing every step.
|
|
|
|
|
|
**Example**
|
|
|
|
|
|
This creates a branch named `osx-redirect` and checks it out.
|
|
|
|
|
|
```
|
... | ... | |