Git is a free and open source distributed version control system. It allows to track changes in source and allows multiple people to work on the same code base.
The repositories are hosted on GitHub.
The analysis code for LCLS is currently hosted in the lcls-psana organization on GitHub.
Once the code is cleaned up and we have less repositories we will move the code to the slac-lcls organization. This organization will also be used by the DAQ group and allows to group all of your code development together.
Setup git
The following steps describe how to setup git. This setup has to done only once for the machine where you are planing to develop code.
- Setting the user name in git:
git config --global user.name "my name"
Setting the email address in git:
git config --global user.email "my email"
Confirm that your user name is correct by:
git config --global user.name
Confirm that your email is correct by:
git config --global user.email
GitHub account
If you do not already have a GitHub account, sign up for a new account on GitHub.
Setup ssh keys for your GitHub account
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
Useful Commands
- Check status of the repo
git status
- Show current and available branches in the repository
git branch -a
Show local changes in the code since the last commit
git diff
Git workflow
The following section describes the workflow for developing software with git.
Clone repository
The first step is to clone the repository you want to contribute by using the flowing command:
git clone git@github.com:lcls-psana/"the repository you want to clone".git
The repository where you clone from is typically called "upstream". This is the global copy of the repository that all developers share and work on together.
Git clone creates a local copy of the repository and any changes that you do to the repository only effect your local copy until you push the changes upstream.
This step only has to be done once.
Make changes to the code
After cloning the repository make changes to the code
Adding new files to the git repo
git add "file"
Create new branch
git checkout -b "new branch"
Commit changes
There are two different ways to commit changes in git: The first way is to automatically stage all files that git is tracking bash git commit -a -m "commit message"
The other option is to specifically stage the files you want to commit bash git add "files that you changed" git commit -m "commit message"
If upstream is ahead of your local version bash git fetch origin git rebase -p origin
if
git rebase --skip ignores local change
change file locally and commit changes
git rebase --continue
git push origin master
More information https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/
Push commits upstream
git push origin "branch name"