version-control

Materials originally developed for the "Version control for research" breakout session of the Best Practice for Code Archiving workshop, 11 December 2016.

View the Project on GitHub tdjames1/version-control

Summary

We’ve introduced the following basic git workflow using git on the command line:

Local operations

Syncing with a remote

Typical use of git in a workflow

To clarify the above, when using git for a project we follow these steps:

  1. Initialise a local repository (git init), or clone an existing remote repository from GitHub (git clone).
  2. Write some code. Save the file to the working directory, e.g. mycode.R
  3. Use git status to see what is ready to add/commit and check file names.
  4. Stage the file using git add mycode.R
  5. Commit the file with a message using git commit -m "My first commit"
  6. Connect your repository to a remote GitHub repo (if you didn’t start off by cloning a repository) or push the code to the remote GitHub repo using git push
  7. Write some more code. Save.
  8. Use git status to see what is ready to add/commit and check file names.
  9. Stage the file using git add mycode.R
  10. Commit the file with a message using git commit -m "Edits to first bit of code"
  11. Push the code to the remote GitHub repo using git push
  12. Write some more code…etc.

Most of the time you’ll just be using four git commands: add, commit, push and status

Going further

Git and GitHub are extremely powerful and flexible systems and there is a lot more you can learn if you wish. Here are some starting points:

Documentation

Tutorials

Cheatsheets and quick reference