/to/project_folder] cd [path
It will help you manage your code most of your files (it is like track changes on steroids: it applies to all files in a folder).
It allows you to trace back your steps: if something breaks, you can figure out what happened.
NO MORE thesis_final_final_SERIOUSLYFINAL.Rmd
a good version control system allows you to collaborate and share!
a good version control system facilitates experimentation!
Distributed Version Control system written by Linus Torvalds (of Linux fame)
Allows you to log updates, branch your work (so you can experiment without losing the original!), and keep all backups, while efficiently using your storage
Gives user a lot of control on what to track, and adds a narrative to changes (‘commit comments’)
Current standard for code
Open Source software written for the command line…
… but many GUI-clients exist nowadays, and most coding IDEs have built-in git.
We have created a repository from a template repository on GitHub.
After that, we cloned the repository to our local PC and moved some of our files into the repository.
Navigate to your project folder in a terminal.
Use Git log to check the history of your project:
Alternatively, via GitHub it is also possible to view the history of your project. Let’s see how a mature project looks like in this repository of the happygitwithr book:
Git status shows you the status of your repository. It tells you which files are created, modified, or deleted relative to the last git snapshot (aka commit) of your project.
Git diff shows you the actual differences between the files that you have changed since the last snapshot.
This command will show you all the commands that you can use with git.
You can now push the content of your local repository to the one on github:
Congrats, you have made your first push and your scripts are online!
\___ THANK YOU!
Take a look at your online repository. Who is the author of your commits? If it is not you, you can configure git to use your identity (make sure github knows this email address):
The .gitignore file in your template contains files that by definition will not be tracked by git.
For example, if you do not want to track a file .DS_Store (always present on my mac), you enter a line like this in your .gitignore file:
Similarly, you can ensure all output in a folder will not be tracked:
Or all files with a certain extension:
NB: There is a .gitkeep file in your template – this does not do the opposite to .gitignore, but is instead used as a placeholder for folders: git does not track empty folders…
Continue moving your files into the file template.
Add, commit, and push all files you want to track! (Do you want to move a tracked file within a git repository? git mv path/to/file.svg newpath/file.svg
and don’t forget to commit!)
Are there (temporary) files you do not wish to track? Add them to the .gitignore file. Consider a .gitignore template for your language: examples on this github repo.
Continue editing your code, and add/commit/push your changes. Can you do it from your IDE?
Experiment with editing and committing on github itself. You can then ‘download’ your code to your local repository using git pull
.
What happens if you edit the same file online and locally, and try to push/pull?
Commits should be atomic: comprehensive ‘units’ of changes.
Commits should have informative messages so you (and others) can trace your steps
Track most files; .gitignore those files you don’t.
Explore new ideas with branches, keep a stable version on main
A version control + git tutorial on Atlassian
A git cheatsheet from Atlassian
A book with all the ins and outs of git from the git website
Workshop Computational Reproducibility