The project is stored in a central repo.
Contributor 1 grabs the most recent version.
Contributor 1 does some new work locally.
Contributor 1 checks if central version changed in the meantime.
Contributor 1 puts their changes in the central repo.
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.
(Check if we have it?)
git --version
which git
where git
$ 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 HomebrewTorvalds (…): "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."
Source: Stackoverflow, Developer Survey Results 2020 [44,328 responses, select all that apply]
Source: Stackoverflow, Developer Survey Results 2021
(30% of those not working with Git say they'd like to)
Source: Stackoverflow, Developer Survey Results 2022 [59,919 responses, select all that apply]
Source: XKCD.
Terminal:
cd pathname
for navigation (cd ..
to go up one level)mkdir foldername
to create a new folderrm
to remove a file and rmdir
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 filesTerminal:
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 also man echo
touch file
to just create a new file (empty)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)
(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.
git init [repo_name]
to initialize an empty repository in the current [or specified] directory
git clone [repo_name] [clone_name]
to create a linked copy of a repository
git config -l
to view all configuration options
Config structure: git config [-l] [--scope] [option_name] [value]
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 settings
Note 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 repository
(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
A .git
folder indicates that you're in a repository.
Never create repositories within repositories!
Be careful about where you hit git init
.
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/
See here for a detailed description
And think of a tree as an ordered collection of files.
Tree | Role |
---|---|
HEAD | Last commit snapshot |
Index | Proposed next commit snapshot |
Working directory | Sandbox |
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.
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)
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.
#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 add [filename(s)]
to add files to the staging area
git add .
to add all new/modified files to the staging area
git commit -m "<commit description>"
to create a new commit with what's in the staging area
At any point you can:
git status
to verify where you are, and what are the differences between the three trees
git diff
to compare last commit with what's in the working directory
git log
to view the commit history
cd ..
git init EX2
(check git status
and git diff
to get a better feel of this)
cd EX2
touch README.md
echo "one line" >> README.md
(check git status
and git diff
to get a better feel of this)
git add README.md
(check git status
and git diff
to get a better feel of this)
git commit -m "Added README.md with one line of text"
(check git status
and git diff
and git log
to get a better feel of this)
git log
, etc. again.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)
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!)
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 press Enter
.
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.
Read more on the three trees with the git reset
guideline
If you need more, just Google tutorials/blog posts/YouTube videos until you find one that makes it clear :) Lots to choose from!