You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

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.

We currently switching from svn to git and the repositories are/will be 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.

GitHub account

If you do not already have a GitHub account, sign up for a new account on GitHub.

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

Setup ssh keys for your GitHub account

To make the development more convenient it is recommended to setup ssh keys for your GitHub account.

Detailed instructions can be found here:

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/


Adding ssh keys can be done in the settings of your GitHub account (top right button on GitHub) and in the settings menu there is a "SSH and PGP keys" section.

Check if you already have an ssh key by checking if the following file exists: ~/.ssh/id_rsa.pub

If yes, create a new ssh key on GitHub and copy the content of ~/.ssh/id_rsa.pub to the Key section.

if you don't already have a ssh key, create a new one with the following command

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Afterwards create a new ssh key on GitHub and copy the content of ~/.ssh/id_rsa.pub to the Key section.

Useful Commands

Check status of the repo

git status

Show current and available branches in the repository

git branch


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"
  • No labels