Someone else is probably wondering the same thing.
I will make mistakes.
Not all of them will be intentional.
git 101
What is git
git is a version control system developed by Linus Torvalds.1
It tracks changes made to files over time.
Installation and setup
Git comes preinstalled on most Linux distributions and macOS.
You can check it is on your system by running which git.
If you are on Windows, or do not have git, check the git docs1 or the GitHub guide to installing git. https://github.com/git-guides/install-git
Setting up a new git repository is beyond the scope of this talk but involves using the git --init command.
We will assume that you have created a repository using an online hosting service (GitLab, GitHub etc.) that provides a nice UI wrapper around the process.
How does it work?
A mental model:
Each time you commit work git stores it as a diff.
This shows specific lines of a file and how they changed (+/-).
This is what you see with the git diff command.
diffs are stored in a tree.
By applying each diff one at a time we can reconstruct files.
We do not need to do this in order
see cherry-picking and merge conflicts…
$ git clone git@github.com:jatkinson1000/git-for-science.github git4sciCloning into 'git4sci'...remote: Enumerating objects: 42, done.remote: Counting objects: 100% (42/42), done.remote: Compressing objects: 100% (39/39), done.remote: Total 42 (delta 26), reused 31 (delta 15), pack-reused 0Receiving objects: 100% (42/42), 69.62 MiB | 5.64 MiB/s, done.Resolving deltas: 100% (26/26), done.$$ cd git4sci/$$ echo "This is a new file." > newfile.txt$
The basic commands
git clone <repo> [<dir>]
Clone a repository into a new directory
git status
Check the state of the directory
git add <filepath>
Update the index with any changes
$ git statusOn branch mainYour branch is up to date with 'origin/main'.Untracked files: (use "git add <file>..." to include in what will be committed) newfile.txtno changes added to commit (use "git add" and/or "git commit -a")$$ git add newfile.txt$$ git statusOn branch mainYour branch is up to date with 'origin/main'.Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: newfile.txt$
The basic commands
git clone <repo> [<dir>]
Clone a repository into a new directory
git status
Check the state of the directory
git add <filepath>
Update the index with any changes
git commit
git commit -m <message>
Commit to record changes in the index
$ git statusOn branch mainYour branch is up to date with 'origin/main'.Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: newfile.txt$$ git commit -m "Add newfile with placeholder text." 1 file changed, 1 insertion(+) create mode 100644 newfile.txt$$ git statusOn branch mainYour branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits)no changes added to commit (use "git add" and/or "git commit -a")$
The basic commands
git clone <repo> [<dir>]
Clone a repository into a new directory
git status
Check the state of the directory
git add <filepath>
Update the index with any changes
git commit
git commit -m <message>
Commit to record changes in the index
git push <remote> <branch>
Send your locally committed changes to the remote repo
$ git statusOn branch mainYour branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits)no changes added to commit (use "git add" and/or "git commit -a")$$ git push origin mainEnumerating objects: 3, done.Counting objects: 100% (3/3), done.Delta compression using up to 8 threadsCompressing objects: 100% (8/8), done.Writing objects: 100% (8/8), 1.89 KiB | 1.89 MiB/s, done.Total 8 (delta 7), reused 0 (delta 0), pack-reused 0remote: Resolving deltas: 100% (7/7), completed with 7 local objects.remote:To github.com:jatkinson1000/git-for-science.git 7647d3a..7ab12ff main -> main$
You are doing some work on pendula and your colleague says they have written some code that solves the equations and they can share with you.
This is made easy by the fact that it is on git!
Let’s see how we get on…