Reference
Git: Reference
Getting Started
Create a new repository on GitHub
Clone that repository locally onto your computer
git clone git@github.com:jacobjameson/simples_script.git
Linear Workflow
cd
into the folder containing your project.cd ~/path/to/project
Check the status of your local repository to make sure you didn’t forget to commit any work.
git status
Then pull the latest changes from the remote repository on GitHub.
git pull
Do a discrete chunk of work on your project (lets say you added a new analysis)
Check the status again, then add the files you’d like to commit to the staging area.
git status git add analysis.R git status
Commit with a descriptive summary of exactly what you did
git commit -m "add new analysis"
Push that change back to GitHub
git push
Non-linear branching workflow
cd
into the folder containing your project.cd ~/path/to/project
Check the status of your local repository to make sure you didn’t forget to commit any work. Run
git branch
to see which branch you’re on. You should ideally be on themaster
branch.git status git branch
Then pull the latest changes from the master branch of the remote repository on GitHub.
git pull
Create a new branch with a descriptive name (remember the
-b
option will create a new branch, you can check out an existing branch by not using that option)git checkout -b analysis-new
Do your work in discrete chunks. at the end of each chunk, add the file to the staging area, then commit it. Its usually a good idea to also push the latest to GitHub, although some people prefer to do that at the end.
Do some work
git status git add analysis.R git commit -m "add blank script" git push git status
Do more work
git status git add analysis.R git commit -m "add code to analysis script" git push git status
Do more work
git status git add analysis.R git commit -m "fixed bug" git push git status
Do more work - lets imagine this work took place across two files, an html file and a stylesheet file.
git status git add analysis.R git add graph.png git commit -m "Added the plot from the analysis" git push git status
Once everything has been pushed to GitHub, issue a pull request from your branch back to the master branch.
You can have a discussion on this pull request using GitHub’s social features, and then merge it into the master branch when everyone agrees its a good idea to do so.
Finally, once the pull request has been merged into the master branch in the remote repository on GitHub, you’ll want to get the latest version of the master branch on your local machine. Checkout the master branch locally and then pull.
git checkout master git pull