git userguide - PIK-LPJmL/LPJmL GitHub Wiki
What is GIT
- By far, the most widely used modern version control system in the world today
- Git has the functionality, performance, security and flexibility that most teams and individual developers need.
GIT and Visusal Studio (external link)
getting the code from GIT
- git clone [email protected]/PIK-LPJmL/LPJmL.git (Download the newest LPJmL Version and sets up git)
- optional: create a new side branch in which you wanna work, you can also work directly in the master but using a side branch is recommended
- You can now either start working with the list of modified files or you add and commit the changes locally. Then you have a clean slate and can start working
For LPJmL Updates in the master branch (when you are working on a side branch):
- git stash (save your untracked changes and stash them away)
- git checkout master (go to the master branch)
- git pull (get update)
- git checkout yourbranch (go back to your branch)
- git stash apply (get your untracked files back)
- git merge master (merge your branch with the master branch)
- take care of marge conflicts and add/commit the final versions
Useful Basic Commands
- git status (shows on what branch you are, staged files and untracked files)
- git diff (shows changes in the files compared to the last commit)
- git clone [email protected]/PIK-LPJmL/LPJmL.git (Download the newest LPJmL Version and sets up git)
- git checkout branch (change to the desired branch, maybe you have to stash your untracked files)
How to pull a new LPJmL Version
- git status
If you have no modified files:
- git pull (svn up)
If you have modified files:
- git stash (stash your modified files away)
- git pull
- git stash apply (get your modified files back)
As a developer: How to commit and push your side branch
- check if you have the newest version (git pull)
- git checkout -b newbranchname (create new side branch)
- git add file (stage the files, you want to commit)
- git commit -m “commitmessage” (locally commit your changes)
- git push origin newbranchname (push to repository)
- merge request in github.com/PIK-LPJmL/LPJmL
- git checkout master
Advanced Commands and Concepts
Pushing only a few files of your working branch to master
In case you worked for a long time on your side branch (your_sidebranch), did regular commits and now you want to push a few files to the master branch to implement your new feature/bugfix.
- git add/commit all your changes to have a clean slate (or git stash)
- git checkout master go back to master, which should be a copy of the repository and have not untracked files
- git checkout -b "newbranch_for_commit" (create a new branch, which is a copy of the master, and goes to this branch)
- git checkout your_sidebranch file1 file2 file3 ... (copy the files from your working side branch to the newbranch_for_commit)
- git add/commit the modified files
- git push origin newbranch_for_commit
- Do a merge request in github
- git checkout your_sidebranch (go back to your working branch and continue to improve LPJmL
Other commands
- git diff master -- myfolder (to compare the changes of a directory in your side branch with the same directory on master, for example all sourcecodes with myfolder = src/)
- git diff --name-status master (to show the different files you have compared to the master branch)