Using Github and Git for Code
From Bridges Lab Protocols
Useful References
- Github cheatsheet - http://help.github.com/git-cheat-sheets/
- Git manual - http://schacon.github.com/git/user-manual.html
- Git installation - http://help.github.com/linux-set-up-git/
- Forking an existing repository - http://help.github.com/fork-a-repo/
Making Changes to Code
- When starting to make changes, to avoid conflicts update your current repository by pulling in the remote branches (presumes branch named master and remote named origin):
git pull origin master
- To check the status of your repository enter:
git status
- To determine the current branches and the names of your remote repository:
git branch
git remote -v
- It is generally best practice to work on a branch for each improvement, then merge that back into a working master branch once you are finished.
- Create a branch. Each branch is a complete clean version of the code, and will not affect other branches. Pick a name that describes the changes you plan to make.
git branch [name of your new branch]
- Switch to that branch
git checkout [name of the branch you want to switch to]
- Make some changes to a file and save it (i use Notepad++ in windows and Gedit or vim in linux)
- Commit the changes. This saves those changes to your revision history. This is useful to find out when changes happened and to go back to when things were working. You want to commit often! Try to make the message useful, as in I did X to Y. Try not to do "changed stuff" or "fixed some mistakes"
git commit -m "This is the message describing the commit"
- Intermittently push those changes back to Github (especially if you are working on a couple of computers; this presumes that your remote is named origin, which is the default):
git push origin [name of your new branch]
- Once you are done working on a branch go back to your original branch (normally master) and pull in changes from your modified branch. Once its working, you can optionally delete the branch if you dont think you are going to need it in the future.
git checkout master git merge [name of your new branch] git branch -d [name of branch you want to delete]