Some advice for myself about git

I’ll put useful tips for myself about the version control software git here. As a start the git users manual can be found here and the LSC DASWG git guide can be found here. These tips are pretty much entirely related to the LAL software library.

  • To create a new branch type git checkout -b branch_name, where branch_name is the name of the new branch you want to create – the -b mean that you automatically switch to that branch [I’ve created a branch called local in all my copies of the lalsuite repository on different clusters in which I’ll do my code development]
  • To switch between branches type git checkout branch_name, where branch_name is the name of the branch you want to switch to
  • To list branches in a repository type git branch – the current branch you are in will be marked with an *
  • To push a copy of a branch to another repository (i.e. if I’ve made changes to the local branch on my local machine and committed those changes, but want to copy those changes to the local branch of the repository on one of the LSC cluster machines) then type [when in the base directory of the repository] git push ssh://cluster.address/gitrepositorydir.git branch_name – so, for example, if I wanted to copy my local local branch of lalsuite to the repository on the UWM cluster I would type [from the lalsuite directory and having run grid-proxy-init] git push ssh://hydra.phys.uwm.edu/home/matthew/lscsoft/lalsuite/.git local. If this fails with an error like: ! [rejected] local -> local (non-fast forward) then try forcing the push by adding a + before the branch name e.g. +local. [Note that you need to have already created the branch you are pushing to and the changes may not show up properly in the repository you are pushing to until you have rechecked-out the branch e.g. if you’ve pushed a local branch to a repository then try git checkout master; git checkout local to see the changes implemented]
  • Another useful thing is git rebase. If you have a branch, e.g. local, that you’ve been doing stuff with, but want to get it back to the same state as the master branch, then when in the local branch do git rebase master.
  • Always useful for resetting things is the git reset --hard HEAD command
  • To get a diff of changes in the form of a patch use git format-patch origin – this will create patch files for all committed changes compared to the origin.

One Reply to “Some advice for myself about git

  1. For completeness, to merge the new branch back into the master when you are finished:
    switch back to the master:
    git checkout master
    then merge
    git merge branch_name

Leave a Reply