flowchart LR A(first version) --> B(some changes) B --> C(Something experimental) B --> D(Bug fix) C --> E(Merge) D --> E linkStyle 1,3 stroke:red;
Getting started with git for version control
2024-07-12
final_version.docx 🎉
final_version_corrected_supervisor1.docx
final_version_corrected_supervisor2.docx
final_version_tookmehourstocombineallcomments.docx 🤯
final_version_corrected.docx
..
flowchart LR A(first version) --> B(some changes) B --> C(Something experimental) B --> D(Bug fix) C --> E(Merge) D --> E linkStyle 1,3 stroke:red;
.git/
flowchart LR A(first version) --commit--> B(some changes) B --new branch--> C(Something experimental) B --commit--> D(Bug fix) C --> E((Merge commit)) D --> E linkStyle 1,3 stroke:red;
git add index.qmd
git commit -m "Adds a paragraph"
Stage and commit in one command:
git commit -am "Adds a paragraph"
git status
git log --oneline
git restore index.qmd
git restore --source fa4f3deac index.qmd
git reset [--soft|--hard|--mixed] fa4f3deac
Sync with a remote (e.g. on GitHub)
All commits are associated with a user
If you’re collaborating:
Make sure to sync with the remote regularly (git pull
+ git push
)
Work with branches and pull requests
Create an empty repository on GitHub
Link your local repository to the created repository:
git remote origin https://github.com/OWNER/REPOSITORY.git
git push -u origin main
.gitignore
enables you to not version control files, e.g.:
_site/
.Rproj.user
Tag a special commit
Typically this is done to create versions, e.g. v1.0.0
With git tag
or creating a release in GitHub
For Zenodo: a DOI is linked to a release
flowchart LR A(commit 1) --> B(commit 2) B --> C(commit 3) C --> D("commit 4 tag:v1.0.0") D --> E(commit 5) style D fill:#f9f,stroke:#333,stroke-width:4px
Work in the main
branch - contains the source files
Use quarto publish gh-pages
to:
Create a branch called gh-pages
and push the rendered html files
Tell GitHub to use the files in gh-pages
to host it as a website
Find your website at OWNER.github.io/REPOSITORY 🚀
GitHub actions: jobs running on the GitHub server that can be triggered by e.g. a push, merge, cron job etc.
Let GitHub actions render the content - ultimate reproducibility
.github/workflows/my_workflow.yml
For most purposes steps have predefined actions
Spend time to learn it! You’ll earn it back quickly 💸
Nice resources:
If you’re new (or smart) use a git client, e.g.:
Rstudio git interface