# What is version control
[I]s the management of changes to documents [...] Changes are usually identified by a number or letter code, termed the "revision number", "revision level", or simply "revision". For example, an initial set of files is "revision 1". When the first change is made, the resulting set is "revision 2", and so on. Each revision is associated with a timestamp and the person making the change. Revisions can be compared, restored, and with some types of files, merged. -- Wiki Diagram of version control
--- # Why do we care Have you ever: - Made a **change to code**, realised it was a **mistake** and wanted to **revert** back? - **Lost code** or had a backup that was too old? - Had to **maintain multiple versions** of a product? - Wanted to see the **difference between** two (or more) **versions** of your code? - Wanted to prove that a particular **change broke or fixed** a piece of code? - Wanted to **review the history** of some code? - Wanted to submit a **change** to **someone else's code**? - Wanted to **share your code**, or let other people work on your code? - Wanted to see **how much work** is being done, and where, when and by whom? - Wanted to **experiment** with a new feature **without interfering** with working code? In these cases, and no doubt others, a version control system should make your life easier. -- [Stackoverflow](https://stackoverflow.com/a/1408464/2097171) (by [si618](https://stackoverflow.com/users/44540/si618)) --- # Git: The stupid content tracker
Git logo
- During this class (and perhaps, the entire program) we will be using [Git](https://git-scm.com). - Git is used by [most developers in the world](https://insights.stackoverflow.com/survey/2018#work-_-version-control). - A great reference about the tool can be found [here](https://git-scm.com/book) - More on what's stupid about git [here](https://en.wikipedia.org/wiki/Git#Naming). --- # How can I use Git There are several ways to include Git in your work-pipeline. A few are: - Through command line - Through one of the available Git GUIs: - RStudio [(link)](https://rstudio.com/products/rstudio/features/) - Git-Cola [(link)](https://git-cola.github.io/) - Github Desktop [(Link)](https://desktop.github.com/) More alternatives [here](https://git-scm.com/download/gui). --- # A Common workflow
Git workflow
A common git workflow
1. Start the session by pulling (possible) updates: `git pull` 2. Make changes a. (optional) Add untracked (possibly new) files: `git add [target file]` b. (optional) Stage tracked files that were modified: `git add [target file]` c. (optional) Revert changes on a file: `git checkout [target file]` 3. Move changes to the staging area (optional): `git add` 4. Commit: a. If nothing pending: `git commit -m "Your comments go here."` b. If modifications not staged: `git commit -a -m "Your comments go here."` 5. Upload the commit to the remote repo: `git push`.