Version Control Tutorial
This tutorial will walk you through setting up a Git repository and using it to collaborate with a partner.
WARNING: Do not post any code in a publicly accessible repo!
- Restarting this tutorial
- Create a local repository
- Create a remote repository
- Add a new file to version control
- Modify a version controlled file
- Daily work flow with version control
- Version control for a team
- Resolving conflicts
We’re assuming that you already have a folder, e.g.,
p1-insta485-static/. It’s OK if there aren’t any files in it yet.
$ pwd /Users/awdeorio/src/eecs280/p1-insta485-static $ ls
You have installed
git. Your version might be different.
$ git --version git version 2.15.1
You have configured your name and email address.
$ git config --global user.name Andrew DeOrio $ git config --global user.email firstname.lastname@example.org
If you need to set your name and email, here’s how.
$ git config --global user.name "YOUR NAME HERE" $ git config --global user.email "YOUR EMAIL HERE"
Restarting this tutorial
If you tried using this tutorial in the past and want to start over, here’s how to delete the files created by
git and how to remove your repository from GitLab.
First, remove your GitLab repository. Browse to your repository’s project page from https://gitlab.eecs.umich.edu/. Select “Settings” -> “Advanced Settings” -> “Remove Project”.
Next, remove the hidden files created by
git. Remember, hidden files start with a dot (
$ pwd /Users/awdeorio/src/eecs280/p1-insta485-static $ rm -rf .git/ .gitignore $ ls -A
Confirm that this is no longer a git repository.
$ git status fatal: Not a git repository (or any of the parent directories): .git
Create a local repository
Navigate to your project directory.
$ pwd /Users/awdeorio/src/eecs280/p1-insta485-static
.gitignore file. This will prevent Git from controlling files like the locally installed Python toolchain. We have a sample for you to download. It’s a hidden file (starts with a dot
.), so you’ll need to use
$ pwd /Users/awdeorio/src/eecs280/p1-insta485-static $ wget https://eecs485staff.github.io/p1-insta485-static/dot_gitignore_sample -O .gitignore .gitignore 100%[===================>] 6.23K --.-KB/s in 0s 2018-01-12 15:15:30 (53.4 MB/s) - ‘.gitignore’ saved [6381/6381] $ ls -A .gitignore
Initialize the repo. You’ll see that the
.gitignore file is untracked.
$ git init Initialized empty Git repository in /Users/awdeorio/src/eecs280/p1-insta485-static/.git/ $ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore nothing added to commit but untracked files present (use "git add" to track)
Add existing files to version control
.gitignore file. See that it is ready to be committed.
$ git add .gitignore $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: .gitignore
Commit the added files to the local repo with the commit message “Initial commit”.
$ git commit -m "Initial commit" [master (root-commit) d11be69] Initial commit 1 file changed, 59 insertions(+) create mode 100644 .gitignore
View the commit log and see our first commit.
$ git log commit d11be699d1389f0f3de4c629195d64bcbf7efb78 (HEAD -> master) Author: Andrew DeOrio <email@example.com> Date: Thu Jan 3 11:16:21 2019 -0500 Initial commit
See that the status is clean.
$ git status On branch master nothing to commit, working tree clean
Create a remote repository
Follow the EECS 280 version control tutorial - Create a remote repository . Be sure to use the correct project name!
Add a new file to version control
Follow the EECS 280 version control tutorial - Add a new file to version control . Note that the folder name will be different. Ignore the part about “visual debugger”.
Modify a version controlled file
Follow the EECS 280 version control tutorial - Modify a version controlled file. Note that the folder name will be different. Edit the README to say whatever you want.