or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Reproducible Research 2 - Git
Wojciech Hardy
link: https://hackmd.io/@WHardy/RR25-git1
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →So what's Git? A Version Control System.
Principles
How does it work? an example
The project is stored in a central repo.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Contributor 1 grabs the most recent version.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Contributor 1 does some new work locally.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Contributor 1 checks if central version changed in the meantime.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Contributor 1 puts their changes in the central repo.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Central repo now stores the new step on top of the previous one.

Contributor 2 joins in and goes through the same steps.

This can go on and on.

And involve a lot more people.

How is this helpful?
GIT general info
Before we start: let's install Git!
(Check if we have it?)
git --version
(on MacOS, this might prompt installation if you don't have Git)
which git
where git
If not there: installation
$ sudo apt install git-all
git --version
might prompt installation in newer OS versions$ xcode-select --install
if you don't have Xcode$ brew install git
using HomebrewAlso check here
Why "Git"? You can actually pick… (citing Wikipedia:)
Torvalds (…): "I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'."
The man page describes Git as "the stupid content tracker".
The read-me file of the source code: "git" can mean anything, depending on your mood.
The source code for Git refers to the program as, "the information manager from hell."
Ouch! In Git's defense
Popularity of different VCS among developers
Source: Stackoverflow, Developer Survey Results 2017
Popularity of collaboration tools among devs
Source: Stackoverflow, Developer Survey Results 2020 [44,328 responses, select all that apply]
Extensively used tools over last year + intention to continue
Source: Stackoverflow, Developer Survey Results 2021
(30% of those not working with Git say they'd like to)
Popularity of Version Control Platforms
Source: Stackoverflow, Developer Survey Results 2022 [59,919 responses, select all that apply]
Let's take a look at a simple project in Git
along with version history (including alternative versions). Short: "repo"
CLI vs GUI
Source: XKCD.
First though, some basic terminal commands
Terminal:
cd pathname
for navigation (cd ..
to go up one level)mkdir foldername
to create a new folderrm
to remove a file andrmdir
to remove a folderdir
to list files/folders in the current path (ls
in OS/Linux/bash)cat file/message
display textdiff file1 file2
show difference between two filesSome additional quick file manipulation
Terminal:
echo text
to print a message>
is a redirection indicator>>
for redirection with appendingecho text > file
to print a text to a file (and overwrite it)echo text >> file
to add new lines to a file. See alsoman echo
touch file
to just create a new file (empty)Exercise 0: terminal (go down for more)
E.g. you can use
cd <pathname>
for navigation or do "Git Bash here" in Windows.mkdir RR_git1
(You can also do it manually)
cd RR_git1
echo "24/2/2025" > classes.txt
(You can also do it manually)
Great! Now that it's covered let's look at Git diagnostics
(also see standard command line options)
git
,git --help
to display git inline helpgit [cmd] --help
to display web help about cmdgit --version
to display diagnostic info (version)git status
to display local repository statusgit log
to display history of commitsThese commands do not alter anything. Feel free to use them frequently to verify and understand the results of your actions.
Basic git commands - setting up the repository
git init [repo_name]
to initialize an empty repository in the current [or specified] directorygit clone [repo_name] [clone_name]
to create a linked copy of a repositorygit config -l
to view all configuration optionsConfig structure:
git config [-l] [--scope] [option_name] [value]
Configuration levels
There are three levels of configuration (i.e. scope):
--system
- pertains to repositories of all system users--global
- pertains to all user's repositories, overrides system settings--local
(default) - pertains to the current repository, overrides global settingsNote 1:
global
configuration will be visible only if you've used Git before (and added some options)Note 2:
local
configuraiton will be visible only if we're in a Git repositoryExercise 1: creating a repository (go down for more)
(hint: you can either initiate it with that name, or create a folder named EX1, enter it, and initiate the repository inside)
git init EX1
cd EX1
or
mkdir EX1
cd EX1
git init
git config -l
git config -l --global
(Note: this will only work if you've ever changed any global options)
git config -l --local
git config --global user.name "Name Surname"
git config --global user.email "your.email@smth.smth"
git config -l --global
git config --local user.name "AB"
git config -l --local
One more thing - check for hidden files
A
.git
folder indicates that you're in a repository.Never create repositories within repositories!
Be careful about where you hit
git init
.The three git states
Unlike the other VCS, Git has something called the "staging area" or "index". This is an intermediate area where commits can be formatted and reviewed before completing the commit.
Source for this and following slides: https://git-scm.com/
The three trees
See here for a detailed description
And think of a tree as an ordered collection of files.
HEAD
HEAD is a snapshot of your last commit on a given branch.
If you want to see what that snapshot looks like, simply type:
git cat-file -p HEAD
If you recall the branch graph, this is the latest commit on the branch.
Staging area aka Index
The index is your proposed next commit.
Command that shows you what your index and working area currently hold (also check options):
git ls-files
It's a box where you put the files you'd like to include in your next commit (sort of a work-in-progress not-yet-commited commit)
Working directory
Think of the working directory as a sandbox, where you can try changes out before sending them to your staging area (index) and then to history.
Ok, so let's examine this process
#0 At this point, only the working directory tree has any content.
#1 We use

git add
to take content in the working directory and copy it to the index.(Note that we keep all boxes. Two currently store the same information)
#2 We use

git commit
, which takes the contents of the index and saves it as a permanent snapshot, creates a commit object which points to that snapshot, and updates master to point to that commit.(In general terms, there's now a new commit on the main branch, and there's an indicator pointing to it saying "hey, this is where we're at".)
#3 If we run
git status
, we’ll see nothing to report, because all three trees are the same.Git commands: the workflow
git add [filename(s)]
to add files to the staging areagit add .
to add all new/modified files to the staging areagit commit -m "<commit description>"
to create a new commit with what's in the staging areaAt any point you can:
git status
to verify where you are, and what are the differences between the three treesgit diff
to compare last commit with what's in the working directorygit log
to view the commit historyExercise 2: adding commits (go down for more)
cd ..
git init EX2
(check
git status
andgit diff
to get a better feel of this)cd EX2
touch README.md
echo "one line" >> README.md
(check
git status
andgit diff
to get a better feel of this)git add README.md
(check
git status
andgit diff
to get a better feel of this)git commit -m "Added README.md with one line of text"
(check
git status
andgit diff
andgit log
to get a better feel of this)Exercise 3: adding commits (go down for more)
git log
, etc. again.Exercise 4: using .gitignore
echo "var1,var2\n1,2" > data/data1.csv
git status
touch .gitignore
echo "data" >> .gitignore
git status
.gitignore is a file that tells git to ignore certain elements. Should we commit it? <- depends on the workflow and, e.g., who we're working with (we might not want to share it with collaborators)
Assignment
While in your EX2 repository, run these four commands:
git status
git log
git ls-files
git ls-files -o
Copy the contents of Bash/CLI starting from
git status
and send them to me in a notepad file (wojciechhardy@uw.edu.pl).Try to store your files in a safe place so we can pick up where we left next time.
Hint: if you simply copy the folder to a pendrive or smth, the repository will continue working (everything you need is already inside!)
Stuck in VIM?
If you forgot about adding a message to your commit, you might have ended up in VIM. It's a free, text-editting software that sometimes feels like a trap.
Tl;dr: hit [ESC], then type
:q
** and pressEnter
.Repeat your commit with a helpful description.
You can also try adding the comment in VIM instead, and then exit with
:wq
instead, which should do the commit with the comment.See more in this helpful Stackoverflow answer.
Useful links
Read more on the three trees with the
git reset
guidelineCheat sheet 1 (Atlassian)
Git-scm in general
Atlassian in general
If you need more, just Google tutorials/blog posts/YouTube videos until you find one that makes it clear :) Lots to choose from!