Version Control

Why do we need to keep track of versions?

Why do we need to keep track of versions?

  • “It broke … hopefully I have a working version somewhere?”
  • “Can you please send me the latest version?”
  • “Where is the latest version?”
  • “Which version are you using?”
  • “Which version have the authors used in the paper I am trying to reproduce?”
  • “Found a bug! Since when was it there?”
  • “I am sure it used to work. When did it change?”
  • “My laptop is gone. Is my thesis now gone?”

Browse an existing project

We will start easy!

Note

  • See a real Git repository and understand what is inside of it.
  • Understand how version control allows advanced inspection of a repository.
  • See how Git allows multiple people to collaborate relatively easily.
  • See the big picture instead of remembering a bunch of commands.

Go to:

https://tinyurl.com/repcorecipes

A word on “Commits”

  • The commit titles are shown in the history of the repository.
  • The title and the message will help us later to understand what we updated and why we updated the code base.

Now that you have started to customise your new GitHub repository, let’s have a look whether we can do that in a bit more convenient way, directly on your computer instead of through the web browser.

Exercises

Explore the Web interface!

  1. How many changes did the Guacamole recipe receive?
  2. Which recipes include the ingredient “salt”?
  3. Who modified each line last and when?
  4. Can you use these recipes yourself? Are you allowed to share modifications?
  5. Browse issues and pull requests in the upstream repository

Summary

  • Git allowed us to understand this simple project much better than we could, if it was just a few files on our own computer.
  • It was easy to share the project with the course.

In the next section we will create our own Git repository!

Creating a Code repository

Git knows two ways of creating an own Git repository.

  1. If you like to have a copy of an existing Git repository that someone else created, you create an own copy by “forking” the repository. This will create a copy of the repository under your GitHub account.

  2. You can create your own GitHub code repository. Simply go to your account and click on the green button “New” under “Your Repositories”

Simple repository templates provided by Utrecht University

  • Python developers: https://github.com/UtrechtUniversity/simple-python-template
  • R developers: https://github.com/UtrechtUniversity/simple-r-project

Working with your repository on your laptop

  • Clone: Create a local copy
  • Pull: Fetch changes in the remote repo
  • Push: Update remote repo with local changes

Update the remote GitHub repository

  • Open the README file
  • Change the contents of the README file and save
  • Check the status git status
  • Prepare to send it off
    • git add README.md
    • git commit -m "Change the README file"

Pushing to GitHub

You can now push the content of your local repository to the one on GitHub:

git push

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):


git config --global user.name "Your Name"
git config --global user.email "your@email.com"

Update the local repository

  • Assume you changed your remote repository through the browser
    • How do you update your local repository?
  • Make another change to your README file in the web browser of GitHub.
  • Now go back to your terminal and do:
git status
git pull

The .gitignore file

  • Located in your local repository .gitignore
  • Lists files and folder which Git should ignore: They are NOT uploaded to GitHub
  • E.g. .DS_Store

Exercises

  • After moving files into your local repository on your computer, run git status to see what Git thinks has changed.

Please note: 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.

  • Run git log to see the history of your project.

  • Can you use Git and push to Github from your IDE?

  • Experiment with editing and committing on GitHub itself (e.g. add something to the README file). You can then ‘download’ your changes to your local repository using git pull.

  • Run git log again to see the history of your project.

  • Optional: What happens if you edit the same file online and locally, and try to push/pull? (Hint: this often causes a ‘merge conflict’, which is no fun to experience. Going through it today means we can assist you if necessary!)

Your turn: Useful git commands

git status

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

Git diff shows you the actual differences between the files that you have changed since the last snapshot.

git --help

This command will show you all the commands that you can use with git.