Setup
Source Files
- Repo
-
github.com/DaraMac/git-masterclass
Downloading Git
- Instructions
- git-scm.com/install
- Linux
- Use package manager
- Mac
- Package manager (brew.sh) or Xcode
- Windows
- Git Bash
Setting Up A Forge
- GitHub
- github.com
- GitLab
- gitlab.com
- Codeberg
- codeberg.org
- Forgejo
- forgejo.org
- SourceHut
- sourcehut.org
- cgit
- git.zx2c4.com/cgit/about
Connecting GitHub
Getting a GUI
- Official list
- git-scm.com/tools/guis
- GitHub Desktop
- github.com/apps/desktop
- Windows
- GitHub desktop (download from link)
- Mac
- GitHub desktop (Brew formula available)
- Linux
- codeberg.org/ckruse/Gitte
Editor Integration
- RStudio
- happygitwithr.com/rstudio-git-github.html
- VSCode
- code.visualstudio.com/docs/sourcecontrol/quickstart
Nicer Command Line
Motivation
Goals
- All your code will be backed up, and be done easily and continually from now on
Version Control
- A way of backing up, and also versioning any text
- A free and fairly easy and quick way to ensure you don’t ever lose your code
- Also keeps track of versions, no more FINAL, FINAL (2), LAST EDIT, COPYv2
- Share and collaborate more easily
- Reproducibility
- Keep everything organised in one place
What to Version Control
-
Everything text
- Code
- Papers (if not already on Overleaf)
- Notes
- Configuration files (dotfiles)
Datasets?
- A small to mid size csv maybe
- Possibly not pure text, so not a good fit for version control systems
- Maybe too big
- But some will be appropriate
- Should be backed up somewhere!
Reproducibility
-
Personal
- Ask yourself, how long would it take to restore your work and working environment on a brand new
machine,
- No need for hypothetical, test right now!
- For other researchers / users
- Licences!
Other Useful Things in Forges
Git
- Most popular and thus well supported and resourced version control system
- xkcd.com/1597
GitHub
- Most popular and thus well supported and resourced git forge
- Not official!
Fun Things
Introduction
Resources
Model
- Distributed version control system (VCS)
- It’s just files in
.git/
- Graphs!
- Hashs
Configuring
git config --global user.name "Your Name"
git config --global user.email
yourEmail@example.com
git config --global push.autoSetupRemote
true
git config --global init.defaultBranch main
git config --list shows current settings
- See book chapter on setting
up and chapter on
configuration for more information
Initialising a Repo
git init
Ignoring
- Create a
.gitignore file and add names
.DS_Store
__pycache__
.Renviron
- Other language or development tool specific files
Cloning
git clone url
- Make sure to clone over SSH for repos you work on
Status
git status
Remotes
git remote
- Add
--verbose or -v for more information
Adding
git add
Committing
git commit
git commit --amend
Pushing
git push
Seeing History
git log
- There’s lots of options to change what you see
Branching
git branch name
-
git switch name
Diffing
git diff
git diff --staged
Pulling
git pull
- Not to be confused with a pull request
Merging
git merge name
- This is the stage where conflicts might occur on multi-user repos
Tagging
git tag name
git push --tags
Throwing Away Changes
Undoing Change
git revert hash
git checkout hash
-- path/to/file
The Nuclear Option
rm -rf
- Then clone the repo again
Next Steps
Collaborating!
- Add other people to private repos
- Or just leave it public
- Find a project that’s interesting to contribute to
- Pull Requests
Hooks
Actions