Git Basic
Git Basic
An Introduction
What is it?
Why should you use it?
How does it work?
What is it?
“Git is a free and open source distributed version
control system, which is fast and efficient.“
- Git Homepage
distributed centralized
http://thepilcrow.net/explaining-basic-concepts-git-and-github/ 2
Why
should
you use
it?
3
Why should you use it?
It helps you!
• Enables collaboration
4
How does it work?
• Repository = database containing all
versions of the files
• Snapshot-based system
• Snapshots are called commits
• Commits are named by checksums
(also used to ensure data integrity) https://git-scm.com/book/en/v2/Getting-Started-Git-Basics
local
common commands
Don’t Panic
This is an log
It is worth it.
7
Gist of this Introduction
Command by command
8
Notation
what follows are commands to be entered on the command
$ line e.g. $ git log
9
$ git help
$ man git-<command>
Works offline!
Advanced:
Aliases
Make your life easier: $ git config --global alias.st „status“
Set up tab completion „Did you mean?“
[Link] $ git config --global help.autocorrect 10
12
$ git init
13
$ git status
Untracked files:
(use "git add <file>..." to include in what will be committed)
hello.cpp
(Output for a newly initialized repo with one new file hello.cpp)
14
$ git add
$ git diff
To be precise: Differences between working directory
and staging area only unstaged changes
17
$ git log
$ git log
18
Basic Workflow
WORK
git add
git commit
19
$ git commit -a
• Parallel development
• Implement new features
• Fix bugs
• Try out something
• Cheap to do in git
(technically just pointers to a commit)
Delete branch
$ git branch -d <branch_name>
Save option to delete a branch, since it prevents data loss
$ git branch -D <branch_name>
Use CAREFULLY! Be sure you want to lose this progress
23
$ git checkout
for branches
24
The HEAD
HEAD = special pointer to currently checked out branch (commit)
https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell
25
$ git diff
Complete Overview
https://www.atlassian.com/git/tutorials/
using-branches/git-merge
27
$ git merge
Fast-forward Three-way
Only three-way
merges have
merge
commits
and potential
merge conflicts
https://www.atlassian.com/git/tutorials/using-branches/git-merge
28
$ git merge
Merge conflicts
$ git merge <branch_name>
Auto-merging <file>
CONFLICT (content): Merge conflict in <file>
Automatic merge failed; fix conflicts and then commit the result.
Update a branch with the new version from the remote repository
$ git pull
… while the branch is checked out
Changes your working directory
$ git blame See line for line, who and which commit is
<file> responsible for the last change to this line
init
checkou
status
t merge status
clone
comm
push
it diff
log
pull
diff --staged
log
36
Good Resources
Beginner:
• Bitbucket Tutorials for git
• Resources to learn by Github (includes interactive tutorials)
• Git Documentation
More advanced:
• Pro Git by Scott Chacon and Ben Straub: THE git book (free)
• Good talk: Introduction to git with Scott Chacon of GitHub
• Good talk: Linus Torvalds (creator of git) on git
37
Summary
config
branch (Not discussed)
init
checkou
status
t merge status
clone
comm
push log
pull
log
Online Slides with the hands-on exercises:
CRC Redmine Z02 Project Wiki or Transport Meeting Website
38