; PSY 1903
PSY 1903 Programming for Psychologists

Git Version Control (Setup)

Version control is software that is used to track changes to a code base over time. Regardless of what industry you’re working in, version control is an essential “best practice” for any programmer, and once you get familiar with version control, you may start to wish you could implement it in all aspects of your work/life!

In this course, we will use a widely used version control program called Git. We will use this in conjunction with Github which is a web service that lets you store and manage code projects that are managed via Git.

Git version control is something that is built into VSCode, so it’s easy to integrate it into your workflow. Before we dig into Git via VSCode, though, there’s a few small configs we have to make to Git on our system via command line, so open your command line program and complete the following steps.

Initial Git configs

In command line, run the following command (edit to use your name) to identify the name to be associated with your Git interactions:

> git config --global user.name "Susan Buck"

Also identify an email (edit to use your email):

> git config --global user.email "susanbuck@fas.harvard.edu"

Run the following command so Git sets up new repositories with a default branch called main (instead of the default master; reason explained here...):

> git config --global init.defaultBranch main

Run this command so that Git will ignore filemode (permission) changes:

> git config --global core.filemode false

Finally, we want to configure how Git handles line endings in files. Following github.com’s recommendations enter one of the following commands:

Mac users:

> git config --global core.autocrlf input

Windows users:

> git config --global core.autocrlf true

That’s it for Git configs; you’re ready for the next step...

Initialize psy1903 as Git repository

In Git, a repository is just a special term for a directory that is being tracked by version control. For our next task, we want to initialize our psy1903 directory as a Git repository and have it published/stored on Github.com. To do that, complete the following steps...

Open the psy1903 directory in VSCode then switch to the Source Control panel by activating it from the icon (three dots connected by lines) in your Activity Bar on the left. Then, click Publish to Github.

If you see a message indicating you need to sign in to Github, click Allow and follow the instructions provided:

After authenticating, you’ll see a dialog offering you the option to publish to either a Private or Public repository. Choose the second option for a Public repository:

After the above process completes, you’ll see confirmation that your repository was successfully published to Github.

Now that your repository has been published to Github, you should be able to see it online at https://github.com/your-username/psy1903.

When using version control, you end up with multiple copies of a repository. In this instance, we have one copy on our local computers. This is your “development“ copy because it is where you will make all changes to your code base.

At the same time, we now have what we’ll call a “central” copy of our repository that exists on Github.com.

Moving forward, whenever we make notable changes to our local “development” repository, we will need to “push” those changes to our central copy on Github so the repositories remain in sync. Steps for this process are covered in the next note set: Git (Usage).

Why multiple copies?

Below are some of the reasons why you have multiple copies of a repository when working with Git version control:

1. Redundancy - Because you have multiple copies of your repository, you have a built-in backup. If your computer dies or you accidentally delete your psy1903 folder locally, you’ll always have that copy on Github.com.

2. Collaboration - Because a copy of your psy1903 folder now exists online, it will be easy to share your code with your classmates and instructors when getting assistance. Collaborators can even clone a copy of your repository onto their computers to work with it directly.

3. Coordinating development - This is beyond the context of our needs, but imagine you were working on a team of developers who all needed to work on the same code base. With a version control system in place, each developer can have their own local development copy, and any changes to the code base will be “checked in” to the central repository on Github.com. As part of this process, Git can inform developers if there are conflicts in the changes they are checking in. This helps developers coordinate and not overwrite each other’s changes. You can also see a history of “check-ins” from each developer so you can see exactly what changes are being made, where they’re being made from, and who made them. For an example of this, check out the “commit history” for the program jsPsych, a utility we’ll explore later in this course.

Key terms

  • Git - A specific type of version control software. Git can be used via the command line or tools built into VSCode. We’re going with the latter approach in this course.
  • Github.com - A web service that lets you host Git repositories online.
  • Repository - A directory that is being tracked by version control
  • Local repository - The copy of our repository that exists on our computers. This is where we will actually make changes to our code base.
  • Central repository - The copy of our repository that exists on Github.com. We will push changes to this repository from our local development repository.
  • Clone - A git term that means to retrieve a copy of a repository.