We've introduced the following basic git workflow using git on the command line:
Local operations
- Staging files:
git add <file> - Committing changes:
git commit - Inspecting your workspace:
git status - Reviewing history:
git log
Syncing with a remote
- Pushing local changes:
git push
To clarify the above, when using git for a project we follow these steps:
- Initialise a local repository (
git init), or clone an existing remote repository from GitHub (git clone). - Write some code. Save the file to the working directory, e.g.
mycode.R - Use
git statusto see what is ready to add/commit and check file names. - Stage the file using
git add mycode.R - Commit the file with a message using
git commit -m "My first commit" - 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 - Write some more code. Save.
- Use
git statusto see what is ready to add/commit and check file names. - Stage the file using
git add mycode.R - Commit the file with a message using
git commit -m "Edits to first bit of code" - Push the code to the remote GitHub repo using
git push - Write some more code...etc.
Most of the time you'll just be using four git commands: add, commit, push and status
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:
git help <command>
- Git - the simple guide http://rogerdudler.github.io/git-guide/
- Version Control with Git http://swcarpentry.github.io/git-novice/
- Pro Git book https://git-scm.com/book/en/v2
- Git reference/cheatsheets https://git-scm.com/docs
- Oh shit git! http://ohshitgit.com/