This is a revised version of Mario Juric's page on git and LSST from http://dev.lsstcorp.org/trac/wiki/GitDemoAndTutorial
The central Stash repositories for Simulations can be found on https://stash.lsstcorp.org/projects/SIM (to
...
clone with write permissions you need to log in)
Access LSST code using git and Stash
...
git status # Note that it says the branch is ahead of origin/master by two commits
git push # This makes the changes available to everyone (they become a part of official LSST code history)
...
git branch # View what branch we're on git branch feature/OPSIM-221 # Create a new branch named 'tickets/9999' git branch # Note that the current branch has not changed git checkout feature/OPSIM-221 # Check out the new branch (like 'svn switch') git branch
or or, you can do it in one line:
git checkout -b feature/OPSIM-221 HEAD # Check out HEAD into a newly created branch 'tickets/....' and switch to it
Adding a file
echo "// still empty" > ExtendedSources.py git add ExtendedSources.py git commit git log
Switching branches
ls -lrt src/image/ # Note the file is there git checkout master # Switch to branch 'master' ls -lrt src/image/ # Note the file is gone
Listing which branches are available
git branch # List local branches git branch -r # List remote branches git branch -a # List all branches (both local and remote)
Making your branches available to others
git push -u origin feature/OPSIM-221 # Push branch feature/..... to remote repository 'origin', and set it up so we can pull from the remote branch in the future (-u)
Use "git pull --rebase" instead of just "git pull" when working on a branch with someone else; this will avoid unnecessary merge commits without rewriting any history that has already been pushed.
Checking out and tracking an existing branch from an upstream repository
git fetch # make sure we're in-sync with remote repositories git checkout -t origin/feature/OPSIM-221 # Checks out the branch 'feature/OPSIM-221' from remote repository 'origin' into a local tracking branch of the same name
# Note: newer versions of git allow just 'git checkout 'feature/OPSIM-221'
or
or
git fetch git checkout -t -b fit origin/feature/OPSIM-221 # Checks out 'feature/OPSIM-221' from remote 'origin' into a local tracking branch named 'fit'
Listing commits on a branch
git log origin/master..origin/feature/OPSIM-221 # Lists commits reachable from 'feature/OPSIM-221'
# that are not reachable from master # (i.e. excludes any commits merged to the # feature from master) git diff origin/master...origin/feature/OPSIM-221 # Displays differences caused by the above
# commits. ***NOTE*** that there are *three* # dots in this syntax, which is unique to # "git diff".
Merging
git checkout master # ensure we're on master git pull # ensure we're up-to-date git merge --no-ff feature/OPSIM-221 # Merge the feature/OPSIM-221 branch
ls -lrt src/image/ # Note the new file is here git log # Show the merge commit git log --graph # This is better git push # Upload changes to main LSST repo
Tagging
git tag -a 5.0.0.0 # Create an annotated tag (a tag with a message)
or
or
git tag -s 5.0.0.0 # Create a gpg-signed tag
...