If you need to: create an account in github and learn the basics with the basic github resources and a cheat sheet. Here you have an overview of what is version control and a an other tutorial, plus some useful ideas on collaborative coding.
Github provides free account upgrades to students and anyone working at a educational/research institute, which allow you to have your own private repositories. To get this upgrade, once you have a personal account, go to this page and fill in the form: https://education.github.com/discount_requests/new
The recommended steps to contribute to a repository are:
- Fork and clone: Get a copy from the GitHub repository
- Update your personal copy
- Track upstream: keeping your copy up-to-date with the main one
- Steps to follow when working on a new (big) feature: Branch, Contribute, Commit, (Merge) and Push.
- Submit a Pull Request to the main a repository code.
Once you have your GitHub account and are familiar with the basic git vocabulary, create your own a repository copy:
-
Go to https://github.com/computationalAstroUAM/[repo name]
-
Click 'Fork' there (right upper corner).
The next step is to get your copy of the repository onto your computer:
-
In your computer, go to your home directory (or wherever you want to have the repository).
-
Clone there the repository, from your OWN local repository:
git clone https://[git username]@github.com/[git username]/[repo name]
You'll be prompt for your GitHub username and password.
Ensure that the remote is the correct one:
git remote -v
If you need to reset the remote link:
git remote set-url origin https://[git username]@github.com/[git username]/[git repository]
Update your personal copy:
git push origin main
This instructions follow the recommendations on syncing a fork from GitHub. To make sure that your version remains up to date with the main version, set the upstream tracking on the command line (change main to the name of your branch):
git remote add --track main upstream https://[git username]@github.com/computationalAstroUAM/[repo name]
Now, every time you need to apply the changes that have been made to the main version to yours, navigate to your a repository directory and run on the command line:
git fetch upstream
git merge upstream/main
To start working on new feature, create a separate feature branch:
git checkout -b feature
You can check the branches you have by:
git branch
And switch between them with:
git checkout main
git checkout feature
Once some changes have been made in the branch, stage them and commit:
git add .
git commit -am "Add a comment here"
If there are conflicts, git will let you know in which files. Open those files and the conflics will be indicated with <<<<<<<. The changes from the HEAD or base branch will appear after the line <<<<<<< HEAD. Next, ======= divides your changes from the changes in the other branch, followed by >>>>>>> BRANCH-NAME. You need to decide what you keep. Once you are done, commit:
git commit -am "Resolved merge conflict."
and continue pushing, requesting a pull request, etc.
You can push changes with:
git push origin feature
Alternatively, you can merge the changes with the main branch first, and then push:
git checkout main
git merge feature
git push origin main
When you are ready to update the main a repository code, go to your GitHub repository page, click "New pull request" to create a Pull Request from your latest commit. It will be applied by someone with administrator main version rights after review.