Version Control Systems
Why is git important for scientists?
Research Stage | Record Keeping |
---|---|
Data Collection & Experiment | Record parameters and changes in lab notebook(paper/digital) |
Data processing & Analysis | ? |
Intro to Git
So what is Git?
Modern VCSs also let you easily (and often automatically) answer questions like2:
- Who wrote this code?
- When was this particular line of this particular file edited? By whom? Why was it edited?
- Over the last 1000 revisions, when/why did this break? (And who broke it?)
In case you get lost check out Further Reading
https://gitimmersion.com/index.html
VS Code Git Workflow Reference
Set Your Identity
In the integrated terminal put the following, but replace it with your name and email.
First Commit
Now we’re going to make our first change, stage that change, and then commit it.
- Open the file called
README.md
.
- Select the git graph icon on the left bar(It should have a blue 1)
- Click on the + button next to
README.md
.
Our change has now been staged! We need to commit it to the git repo
- Type a message into the “Message” box (“Add README” would be a great message)
- Hit
Ctrl+Enter
That was the first commit!
Second commit
Ctrl+p
and selectREADME.md
.- This is a handy way to jump between files in VS Code
- Change the file to have
- Select the git graph icon on the left bar(It should have a blue 1)
- Click on the + button next to
README.md
.
This time we staged some changes we didn’t mean to. We need to remove those and break our commits up into logical sections, rather than commit everything at once.
- Click on the - button next to
README.md
under Staged Changes.
That just unstaged what we staged before we commited it.
- Click on
README.md
and this will pull up a diff, which is the difference between what’s committed to the repo, and the working copy. - Highlight the 3 and 4 lines, right click and select “Stage Selected Ranges”
- We want to get rid of the mistake we staged, so click on
README.md
under “Staged Changes”, highlight line 2(“This is a mistake!”), right click and select “Unstage Selected Ranges”.
Now we want to commit our changes:
- Type a message into the “Message” box (“Update README” would be a great message)
- Hit
Ctrl+Enter
Now for practice, commit only the line that has “This will be the third commit”
Viewing changes
This may not work on Sysbio becasue the git version is too old.
- In the Source Control window, open the “COMMITS” drawer. You should see
- You can click though the “FILE HISTORY” and view old versions of the file
So what’s a remote?
As you probably know, git is a distributed version control system. Most operations are done locally. To communicate with the outside world, git uses what are called remotes. These are repositories other than the one on your local disk which you can push your changes into (so that other people can see them) or pull from (so that you can get others changes). The command git remote add origin [email protected]:peter /first_app.gitcreates a new remote called origin located at [email protected]:peter /first_app.git. Once you do this, in your push commands, you can push to origin instead of typing out the whole URL. 3
Creating a remote
- Create a GitHub account
- On the left hand side you should see Repositories and a green button that says New. Click it.
- Give the repo a name.
ag-intro
is recommended. - Copy the code underneath “…or push an existing repository from the command line” Should be something similar to:
- In VS Code hit
Ctrl+Shift+~
, this should open up a terminal in the bottom of the screen. Paste the commands in there. - Check your GitHub repo and see if the code got pushed!
Further Reading
- Missing Semester Version Control lecture
- Pro Git Book
- Resources to learn Git
- GitHub Training Manual
- Git by Example
- githowto
Footnotes
-
04-git_workshop of HPC ↩