SlideShare a Scribd company logo
/tutorial/git
Thomas Rausch
thomas.rausch@tuwien.ac.at
Institute for Information Systems
Distributed Systems Group
TU Wien
http://git-scm.com
Of Linus and learning curves
“Linus is a guy who delights in being cruel to people …”
Of Linus and learning curves
“Linus is a guy who delights in being cruel to people …”
“His latest cruel act is to create a revision control system
which is expressly designed to make you feel less
intelligent than you thought you were” [1]
[1]: Tech Talk: Linus Torvalds on git - http://youtu.be/4XpnKHJAok8
Of Linus and learning curves
What you should take from today
What you should take from today
git =
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
$ git config --global user.name "Thomas Rausch"
$ git config --global user.email thomas@rauschig.org
Configure your user
basics stages branch merge remotes advanced
$ git init
Initialized empty Git repository in /home/thomas/git-tutorial/.git/
Initialize an empty repository
$ git clone <repo> [<directory>]
Clone a remote repository
basics stages branch merge remotes advanced
Check the status of your repository
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README.md
# src/
nothing added to commit but untracked files present (use "git add" to track)
$ git status -sb
# Initial commit on master
?? README.md
?? src
basics stages branch merge remotes advanced
$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.md
#
$ git add README.md
Start tracking files
basics stages branch merge remotes advanced
Commit changes
$ git status
# On branch master
nothing to commit (working directory clean)
$ git commit -m "add readme file"
[master (root-commit) d4c59ff] add readme file
1 file changed, 3 insertions(+)
create mode 100644 README.md
basics stages branch merge remotes advanced
View differences of current unstaged modifications
$ git diff --color
diff --git a/src/Main.java b/src/Main.java
index 66c8e93..dcdf6cb 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -1,5 +1,7 @@
class Main {
+ static int status = 0;
+
public static void main(String[] args) {
- System.exit(0);
+ System.exit(status);
}
}
basics stages branch merge remotes advanced
Unstaging files
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: src/HelloWien.java
# new file: src/HelloWorld.java
$ git reset HEAD src/HelloWien.java
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: src/HelloWorld.java
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# src/HelloWien.java
#
basics stages branch merge remotes advanced
Undoing local unstaged changes
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README.md
$ git checkout -- README.md
$ git status
# On branch master
nothing to commit (working directory clean)
basics stages branch merge remotes advanced
Viewing the history
$ git log
commit 9c3cb834c43d67cc37b15e74b64dc830c1e78199
Author: Thomas Rausch <thomas@rauschig.org>
Date: Mon Oct 14 00:04:53 2013 +0100
modified readme file
commit d4c59ffd7e676dad6aef2cc244b87e3c579aa904
Author: Thomas Rausch <thomas@rauschig.org>
Date: Sun Oct 13 23:45:39 2013 +0100
add readme file
$ git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d
%Creset %Cgreen(%cr)%Creset' --abbrev-commit -date=relative
* 9c3cb83 Thomas Rausch: modified readme file - (HEAD, master) (4 minutes ago)
* d4c59ff Thomas Rausch: add readme file - (24 minutes ago)
$ git log --oneline
9c3cb83 modified readme file
d4c59ff add readme file
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
working directory
basics stages branch merge remotes advanced
working directory
staging area
basics stages branch merge remotes advanced
working directory
staging area
repository
basics stages branch merge remotes advanced
working directory
staging area
repository
git add
basics stages branch merge remotes advanced
working directory
staging area
repository
git add
git commit
basics stages branch merge remotes advanced
working directory
staging area
repository
git commit -a
basics stages branch merge remotes advanced
working directory
staging area
repository
basics stages branch merge remotes advanced
git reset HEAD <file>
working directory
staging area
repository
git reset HEAD <file> git checkout
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
$ git branch
develop
* master
new-feature
List branches
basics stages branch merge remotes advanced
$ git branch
develop
* master
new-feature
List branches
Branch you have
currently
checked out
basics stages branch merge remotes advanced
$ git checkout develop
Switched to branch 'develop'
Change into a branch
basics stages branch merge remotes advanced
Manage branches
$ git branch <branch>
Create a new branch from the one you have currently checked out
$ git branch -m <oldbranch> <newbranch>
Rename a branch
$ git branch -D <branch>
Delete a branch
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
Merge branches
$ git checkout master
$ git merge topic
Merge the specified branch into the current branch (the one you have checked out)
Merges topic
into master
basics stages branch merge remotes advanced
master
topic
master
topic
basics stages branch merge remotes advanced
master
topic
master
topic
Fast-forward
topic
basics stages branch merge remotes advanced
master
master, topic
Fast-forward
basics stages branch merge remotes advanced
master
topic
master
topic
basics stages branch merge remotes advanced
master
topic
master
topic
Recursive three-way
basics stages branch merge remotes advanced
master
topic
A merge commit
with 2 parents
Recursive three-way
basics stages branch merge remotes advanced
Conflicts
basics stages branch merge remotes advanced
master
basics stages branch merge remotes advanced
class Main {
public static void main(String... args) {
}
}
master
basics stages branch merge remotes advanced
class Main {
public static void main(String... args) {
}
}
master topic
basics stages branch merge remotes advanced
class Main {
public static void main(String... args) {
}
}
class Main {
static int status = 0;
public static void main(String... args) {
System.exit(status);
}
}
master topic
basics stages branch merge remotes advanced
class Main {
public static void main(String... args) {
System.exit(0);
}
}
class Main {
public static void main(String... args) {
}
}
class Main {
static int status = 0;
public static void main(String... args) {
System.exit(status);
}
}
master topic
basics stages branch merge remotes advanced
class Main {
public static void main(String... args) {
System.exit(0);
}
}
class Main {
public static void main(String... args) {
}
}
class Main {
static int status = 0;
public static void main(String... args) {
System.exit(status);
}
}
class Main {
static int status = 0;
public static void main(String... args) {
<<<<<<< HEAD
System.exit(0);
=======
System.exit(status);
>>>>>>> topic
}
}
master topic
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
master
develop
topic (features)
basics stages branch remotes advanced
master
merge
basics stages branch remotes advanced
git branch develop
master
develop
merge
basics stages branch remotes advanced
master
develop
merge
basics stages branch remotes advanced
master
develop
merge
basics stages branch remotes advanced
master
develop
feature
git branch featureX
merge
basics stages branch remotes advanced
master
develop
feature
feature
git branch featureY
merge
basics stages branch remotes advanced
master
develop
feature
feature
git branch featureY
merge
basics stages branch remotes advanced
master
develop
feature
feature
git merge featureX
merge
basics stages branch merge remotes advanced
master
develop
feature
feature
git merge develop
basics stages branch merge remotes advanced
master
develop
feature
feature
version 1.0
basics stages branch merge remotes advanced
master
develop
feature
feature
git merge develop
downmerge
basics stages branch merge remotes advanced
master
develop
feature
feature
version 2.0
basics stages branch merge remotes advanced
master
develop
feature
feature
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
working directory
staging area
repository
basics stages branch merge remotes advanced
working directory
staging area
local repository
remote repository
basics stages branch merge remotes advanced
working directory
staging area
local repository
remote repository
working directory
staging area
local repository
working directory
staging area
local repository
developer developer developer
basics stages branch merge remotes advanced
working directory
staging area
local repository
remote repository
working directory
staging area
local repository
working directory
staging area
local repository
developer developer developer
origin
basics stages branch merge remotes advanced
working directory staging area local repository remote repository
basics stages branch merge remotes advanced
working directory staging area local repository remote repository
git add/mv/rm
git commit
git commit -a
git reset <file>
git checkout <branch>
basics stages branch merge remotes advanced
working directory staging area local repository remote repository
git push
git add/mv/rm
git commit
git commit -a
git reset <file>
git checkout <branch>
basics stages branch merge remotes advanced
working directory staging area local repository remote repository
git push
git fetch
git add/mv/rm
git commit
git commit -a
git reset <file>
git checkout <branch>
basics stages branch merge remotes advanced
working directory staging area local repository remote repository
git push
git fetch
git pull
git add/mv/rm
git commit
git commit -a
git reset <file>
git checkout <branch>
basics stages branch merge remotes advanced
Subversion
working
directory
basics stages branch merge remotes advanced
Subversion
working
directory
remote
repository
basics stages branch merge remotes advanced
commit
Subversion
working
directory
remote
repository
basics stages branch merge remotes advanced
updatecommit
Subversion
working
directory
remote
repository
basics stages branch merge remotes advanced
updatecommit
working
directory
Subversion Git
working
directory
remote
repository
basics stages branch merge remotes advanced
updatecommit
local
repository
working
directory
Subversion Git
working
directory
remote
repository
basics stages branch merge remotes advanced
updatecommit
local
repository
working
directory
remote
repository
Subversion Git
working
directory
remote
repository
basics stages branch merge remotes advanced
Distribution models
basics stages branch merge remotes advanced
Distribution models
Centralized workflow
origin
basics stages branch merge remotes advanced
Distribution models
Centralized workflow
origin
GitHub Forking/Pull Request
dictator
basics stages branch merge remotes advanced
Distribution models
Centralized workflow
origin
GitHub Forking/Pull Request
upstream
dictator developers
fork
origin
basics stages branch merge remotes advanced
Distribution models
Centralized workflow
origin
GitHub Forking/Pull Request
upstream
dictator developers
fork
origin
basics stages branch merge remotes advanced
Distribution models
Centralized workflow
origin
GitHub Forking/Pull Request
Pull request
upstream
dictator developers
origin
fork
basics stages branch merge remotes advanced
Distribution models
Centralized workflow
origin
GitHub Forking/Pull Request
Pull request
upstream
dictator developers
origin
fork
Many others
basics stages branch merge remotes advanced
Managing remotes
$ git remote -v
origin git@github.com:thrau/openengsb-framework.git (fetch)
origin git@github.com:thrau/openengsb-framework.git (push)
upstream git@github.com:openengsb/openengsb-framework.git (fetch)
upstream git@github.com:openengsb/openengsb-framework.git (push)
$ git remote add <name> <url>
$ git remote rm <name>
basics stages branch merge remotes advanced
Remote tracking branches
$ git branch -a
basics stages branch merge remotes advanced
Remote tracking branches
$ git branch -a
* master
my-local-feature
remotes/origin/master
basics stages branch merge remotes advanced
Remote tracking branches
$ git branch -a
* master
my-local-feature
remotes/origin/master
originlocal
master
master,
origin/master
basics stages branch merge remotes advanced
Remote tracking branches
$ git branch -a
* master
my-local-feature
remotes/origin/master
originlocal
master
master,
origin/master
basics stages branch merge remotes advanced
Remote tracking branches
$ git branch -a
* master
my-local-feature
remotes/origin/master
master
origin/master
originlocal
master
basics stages branch merge remotes advanced
Remote tracking branches
$ git push
master,
origin/master
originlocal
master
basics stages branch merge remotes advanced
Delete remote branches
$ git push origin :branchname
basics stages branch merge remotes advanced
Delete local tracking branches
$ git fetch origin --prune
basics stages branch merge remotes advanced
Dealing with remote conflicts
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
master,
origin/master
originlocal
master
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
To ssh://thomas@localhost/home/thomas/git-remote
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
To ssh://thomas@localhost/home/thomas/git-remote
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull origin master
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
To ssh://thomas@localhost/home/thomas/git-remote
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull origin master
… fix merge conflicts ...
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
To ssh://thomas@localhost/home/thomas/git-remote
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull origin master
… fix merge conflicts ...
$ git commit -am "Merge remote branch 'master'"
$ git push origin master
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
To ssh://thomas@localhost/home/thomas/git-remote
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull origin master
… fix merge conflicts ...
$ git commit -am "Merge remote branch 'develop'"
$ git push origin master
Produces a
merge commit
basics stages branch merge remotes advanced
Dealing with remote conflicts
$ git push origin master
To ssh://thomas@localhost/home/thomas/git-remote
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git pull --rebase origin master
… fix merge conflicts ...
$ git rebase --continue
repeat
$ git push origin master
Rewrites the
history.
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
Rewriting history
basics stages branch merge remotes advanced
Rewriting history
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Rewriting history
master
topic
master
topic
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Rewriting history
master
topic
“base”
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Rewriting history
master
topic
“base”
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Rewriting history
master
topic
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Rewriting history
master
topic
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Rewriting history
master
topic
“base”
* * **
* new commits
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Rewriting history
master
topic * * **
Avoid changing
published histories!
$ git rebase master
Rebase the current branch on to the tip of a different one
basics stages branch merge remotes advanced
Ups, I forgot something
basics stages branch merge remotes advanced
Ups, I forgot something
$ git commit --amend -a
Add all your current changes to the previous commit
basics stages branch merge remotes advanced
Ups, I forgot something
$ git commit --amend -a
$ git commit --amend -m "new commit message"
Reword the last commit
Add all your current changes to the previous commit
basics stages branch merge remotes advanced
Ups, I forgot something
$ git commit --amend -a
Add all your current changes to the previous commit
$ git commit --amend -m "new commit message"
Reword the last commit
Avoid changing
published histories!
basics stages branch merge remotes advanced
Pushing a rewritten history
$ git push --force origin <branch>
Danger zone! Overwrites the remote history with your local one. Remote commits may get lost!
basics stages branch merge remotes advanced
When that merge came in like a wrecking ball
$ git merge --abort
$ git rebase --abort
Abort an initiated merge or rebase
basics stages branch merge remotes advanced
Git tag
$ git tag
Show all tags
$ git tag -a v2.0
Tag the current commit with an annotation
Tag (mark) important points in the commit history, e.g. when a working version is released
$ git push origin --tags
Push tags to the remote
basics stages branch merge remotes advanced
Ignoring files
Create a file in your repository (and add & commit it) named .gitignore, containing paths and
rules that tell git which files to ignore.
# Maven files
target/
bin/
# Eclipse project files
.project
.classpath
.settings
# Mac OS
.DS_Store
# IntelliJ IDEA files
*.iml
*.ipr
*.iws
.idea
# backup-files
*~
basics stages branch merge remotes advanced
Writing good commit messages
basics stages branch merge remotes advanced
Writing *bad* commit messages
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
“:(:(“
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
“:(:(“
“changes”
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
“:(:(“
“changes”
“it works!”
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
“:(:(“
“changes”
“it works!”
“final commit”
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
“:(:(“
“changes”
“it works!”
“final commit”
“Testing in progress ;-)”
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
“:(:(“
“changes”
“it works!”
“final commit”
“Testing in progress ;-)”
“TODO: write meaningful commit message”
basics stages branch merge remotes advanced
Writing *bad* commit messages
”fix”
“:(:(“
“changes”
“it works!”
“final commit”
“Testing in progress ;-)”
“TODO: write meaningful commit message”
“Your commit is writing checks your merge can't cash”
basics stages branch merge remotes advanced
Writing good commit messages
Write commit messages as if you're giving commands to the codebase
basics stages branch merge remotes advanced
Writing good commit messages
Write commit messages as if you're giving commands to the codebase
“Add DAO interfaces for Entities“
basics stages branch merge remotes advanced
Writing good commit messages
Write commit messages as if you're giving commands to the codebase
“Add DAO interfaces for Entities“
“Implement basic version of AddressDAO”
basics stages branch merge remotes advanced
Writing good commit messages
Write commit messages as if you're giving commands to the codebase
“Add DAO interfaces for Entities“
“Implement basic version of AddressDAO”
“Fix bug in delete method of UserDAO”
“Move package security to at.ac.tuwien.service”
“Add generated fxml files for UI”
basics stages branch merge remotes advanced
basics stages branch merge remotes advanced
Other great tutorials
●
Official Git Documentation
http://git-scm.com/doc
●
TryGit – An interactive Git tutorial
http://try.github.io
●
Git Immersion
http://gitimmersion.com/
●
Atlassian Git Tutorials
https://www.atlassian.com/git
●
Git Cheatsheet – Command categorisation
http://ndpsoftware.com/git-cheatsheet.html
●
LearnGitBranching
http://pcottle.github.io/learnGitBranching
Further reading
●
A successful Git branching model
http://nvie.com/posts/a-successful-git-branching-model/
●
Changing history, or How to Git pretty
http://justinhileman.info/article/changing-history
●
Reset Demystified
http://git-scm.com/blog/2011/07/11/reset.html
●
Avoiding Git Disasters: A Gory Story
http://randyfay.com/node/89
●
A Rebase Workflow for Git
http://randyfay.com/node/91
Headache?
Questions?
fin
Thanks for listening - Enjoy git!
Feedback appreciated
thomas.rausch@tuwien.ac.at

More Related Content

What's hot (20)

PDF
Git and github 101
Senthilkumar Gopal
 
PDF
Git and git flow
Fran García
 
PDF
Github - Git Training Slides: Foundations
Lee Hanxue
 
PDF
Git training v10
Skander Hamza
 
PDF
Git Version Control System
KMS Technology
 
PPTX
Git in 10 minutes
Safique Ahmed Faruque
 
PPTX
Git - Basic Crash Course
Nilay Binjola
 
PPTX
Basic Git Intro
Yoad Snapir
 
PPTX
Git and git workflow best practice
Majid Hosseini
 
PPTX
Intro to git and git hub
Venkat Malladi
 
PDF
Git Series. Episode 3. Git Flow and Github-Flow
Mikhail Melnik
 
PDF
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
PPTX
Git 101 for Beginners
Anurag Upadhaya
 
PDF
Git - An Introduction
Behzad Altaf
 
PDF
Git basics
GHARSALLAH Mohamed
 
PDF
Git flow
Valerio Como
 
PDF
Git flow Introduction
David Paluy
 
PPT
Git basic
Emran Ul Hadi
 
PDF
Advanced Git Tutorial
Sage Sharp
 
PPTX
Source control
Sachithra Gayan
 
Git and github 101
Senthilkumar Gopal
 
Git and git flow
Fran García
 
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git training v10
Skander Hamza
 
Git Version Control System
KMS Technology
 
Git in 10 minutes
Safique Ahmed Faruque
 
Git - Basic Crash Course
Nilay Binjola
 
Basic Git Intro
Yoad Snapir
 
Git and git workflow best practice
Majid Hosseini
 
Intro to git and git hub
Venkat Malladi
 
Git Series. Episode 3. Git Flow and Github-Flow
Mikhail Melnik
 
Git-flow workflow and pull-requests
Bartosz Kosarzycki
 
Git 101 for Beginners
Anurag Upadhaya
 
Git - An Introduction
Behzad Altaf
 
Git basics
GHARSALLAH Mohamed
 
Git flow
Valerio Como
 
Git flow Introduction
David Paluy
 
Git basic
Emran Ul Hadi
 
Advanced Git Tutorial
Sage Sharp
 
Source control
Sachithra Gayan
 

Similar to Git Introduction Tutorial (20)

PDF
GIT_In_90_Minutes
vimukthirandika
 
PDF
Git Concepts, Commands and Connectivity
Raja Soundaramourty
 
PDF
Git_real_slides
Khanh NL-bantoilatoi
 
PDF
Git real slides
Lucas Couto
 
PPT
Git-GitHub.ppt for teaching all college stidents
DHRUV618361
 
PDF
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
PPT
Report about the dangers of git and github on the environment
lameche1islam
 
PPT
Git-GitHub.ppt Diploma in computer. engineering
Roshankumar558219
 
PPT
Distributed Version control using Git and Github
RikinBasu1
 
PDF
Pro git - grasping it conceptually
seungzzang Kim
 
PPTX
Git walkthrough
Bimal Jain
 
PDF
Getting some Git
BADR
 
PPTX
Working with Git
Sanghoon Hong
 
PDF
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
PPTX
Git 101 - An introduction to Version Control using Git
John Tighe
 
PDF
Source Code Management with Git
Things Lab
 
PPTX
GIT presentation
Naim Latifi
 
PPTX
Introduction to Git and GitHub
Bioinformatics and Computational Biosciences Branch
 
PPTX
Git workshop
Mateusz Galazyn
 
PPT
B4usolution git git-hub
b4usolution .
 
GIT_In_90_Minutes
vimukthirandika
 
Git Concepts, Commands and Connectivity
Raja Soundaramourty
 
Git_real_slides
Khanh NL-bantoilatoi
 
Git real slides
Lucas Couto
 
Git-GitHub.ppt for teaching all college stidents
DHRUV618361
 
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
Report about the dangers of git and github on the environment
lameche1islam
 
Git-GitHub.ppt Diploma in computer. engineering
Roshankumar558219
 
Distributed Version control using Git and Github
RikinBasu1
 
Pro git - grasping it conceptually
seungzzang Kim
 
Git walkthrough
Bimal Jain
 
Getting some Git
BADR
 
Working with Git
Sanghoon Hong
 
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Git 101 - An introduction to Version Control using Git
John Tighe
 
Source Code Management with Git
Things Lab
 
GIT presentation
Naim Latifi
 
Git workshop
Mateusz Galazyn
 
B4usolution git git-hub
b4usolution .
 
Ad

More from Thomas Rausch (9)

PDF
Test cloud application deployments locally and in CI without staging environm...
Thomas Rausch
 
PDF
Synthesizing Plausible Infrastructure Configurations for Evaluating Edge Comp...
Thomas Rausch
 
PDF
Towards a Serverless Platform for Edge AI
Thomas Rausch
 
PDF
Edge Intelligence: The Convergence of Humans, Things and AI
Thomas Rausch
 
PDF
Portable Energy-Aware Cluster-Based Edge Computers
Thomas Rausch
 
PDF
EMMA: Distributed QoS-Aware MQTT Middleware for Edge Computing Applications
Thomas Rausch
 
PDF
Message-Oriented Middleware for Edge Computing Applications
Thomas Rausch
 
PDF
An Empirical Analysis of Build Failures in the Continuous Integration Workflo...
Thomas Rausch
 
PDF
Build Failure Prediction in Continuous Integration Workflows
Thomas Rausch
 
Test cloud application deployments locally and in CI without staging environm...
Thomas Rausch
 
Synthesizing Plausible Infrastructure Configurations for Evaluating Edge Comp...
Thomas Rausch
 
Towards a Serverless Platform for Edge AI
Thomas Rausch
 
Edge Intelligence: The Convergence of Humans, Things and AI
Thomas Rausch
 
Portable Energy-Aware Cluster-Based Edge Computers
Thomas Rausch
 
EMMA: Distributed QoS-Aware MQTT Middleware for Edge Computing Applications
Thomas Rausch
 
Message-Oriented Middleware for Edge Computing Applications
Thomas Rausch
 
An Empirical Analysis of Build Failures in the Continuous Integration Workflo...
Thomas Rausch
 
Build Failure Prediction in Continuous Integration Workflows
Thomas Rausch
 
Ad

Recently uploaded (20)

PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Executive Business Intelligence Dashboards
vandeslie24
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 

Git Introduction Tutorial

  • 1. /tutorial/git Thomas Rausch [email protected] Institute for Information Systems Distributed Systems Group TU Wien
  • 3. Of Linus and learning curves “Linus is a guy who delights in being cruel to people …”
  • 4. Of Linus and learning curves “Linus is a guy who delights in being cruel to people …” “His latest cruel act is to create a revision control system which is expressly designed to make you feel less intelligent than you thought you were” [1] [1]: Tech Talk: Linus Torvalds on git - http://youtu.be/4XpnKHJAok8
  • 5. Of Linus and learning curves
  • 6. What you should take from today
  • 7. What you should take from today git =
  • 8. basics stages branch merge remotes advanced
  • 9. basics stages branch merge remotes advanced
  • 10. basics stages branch merge remotes advanced $ git config --global user.name "Thomas Rausch" $ git config --global user.email [email protected] Configure your user
  • 11. basics stages branch merge remotes advanced $ git init Initialized empty Git repository in /home/thomas/git-tutorial/.git/ Initialize an empty repository $ git clone <repo> [<directory>] Clone a remote repository
  • 12. basics stages branch merge remotes advanced Check the status of your repository $ git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README.md # src/ nothing added to commit but untracked files present (use "git add" to track) $ git status -sb # Initial commit on master ?? README.md ?? src
  • 13. basics stages branch merge remotes advanced $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: README.md # $ git add README.md Start tracking files
  • 14. basics stages branch merge remotes advanced Commit changes $ git status # On branch master nothing to commit (working directory clean) $ git commit -m "add readme file" [master (root-commit) d4c59ff] add readme file 1 file changed, 3 insertions(+) create mode 100644 README.md
  • 15. basics stages branch merge remotes advanced View differences of current unstaged modifications $ git diff --color diff --git a/src/Main.java b/src/Main.java index 66c8e93..dcdf6cb 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,7 @@ class Main { + static int status = 0; + public static void main(String[] args) { - System.exit(0); + System.exit(status); } }
  • 16. basics stages branch merge remotes advanced Unstaging files $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: src/HelloWien.java # new file: src/HelloWorld.java $ git reset HEAD src/HelloWien.java $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: src/HelloWorld.java # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # src/HelloWien.java #
  • 17. basics stages branch merge remotes advanced Undoing local unstaged changes $ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.md $ git checkout -- README.md $ git status # On branch master nothing to commit (working directory clean)
  • 18. basics stages branch merge remotes advanced Viewing the history $ git log commit 9c3cb834c43d67cc37b15e74b64dc830c1e78199 Author: Thomas Rausch <[email protected]> Date: Mon Oct 14 00:04:53 2013 +0100 modified readme file commit d4c59ffd7e676dad6aef2cc244b87e3c579aa904 Author: Thomas Rausch <[email protected]> Date: Sun Oct 13 23:45:39 2013 +0100 add readme file $ git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d %Creset %Cgreen(%cr)%Creset' --abbrev-commit -date=relative * 9c3cb83 Thomas Rausch: modified readme file - (HEAD, master) (4 minutes ago) * d4c59ff Thomas Rausch: add readme file - (24 minutes ago) $ git log --oneline 9c3cb83 modified readme file d4c59ff add readme file
  • 19. basics stages branch merge remotes advanced
  • 20. basics stages branch merge remotes advanced
  • 21. working directory basics stages branch merge remotes advanced
  • 22. working directory staging area basics stages branch merge remotes advanced
  • 23. working directory staging area repository basics stages branch merge remotes advanced
  • 24. working directory staging area repository git add basics stages branch merge remotes advanced
  • 25. working directory staging area repository git add git commit basics stages branch merge remotes advanced
  • 26. working directory staging area repository git commit -a basics stages branch merge remotes advanced
  • 27. working directory staging area repository basics stages branch merge remotes advanced git reset HEAD <file>
  • 28. working directory staging area repository git reset HEAD <file> git checkout basics stages branch merge remotes advanced
  • 29. basics stages branch merge remotes advanced
  • 30. basics stages branch merge remotes advanced
  • 31. basics stages branch merge remotes advanced
  • 32. basics stages branch merge remotes advanced $ git branch develop * master new-feature List branches
  • 33. basics stages branch merge remotes advanced $ git branch develop * master new-feature List branches Branch you have currently checked out
  • 34. basics stages branch merge remotes advanced $ git checkout develop Switched to branch 'develop' Change into a branch
  • 35. basics stages branch merge remotes advanced Manage branches $ git branch <branch> Create a new branch from the one you have currently checked out $ git branch -m <oldbranch> <newbranch> Rename a branch $ git branch -D <branch> Delete a branch
  • 36. basics stages branch merge remotes advanced
  • 37. basics stages branch merge remotes advanced
  • 38. basics stages branch merge remotes advanced
  • 39. basics stages branch merge remotes advanced Merge branches $ git checkout master $ git merge topic Merge the specified branch into the current branch (the one you have checked out) Merges topic into master
  • 40. basics stages branch merge remotes advanced master topic master topic
  • 41. basics stages branch merge remotes advanced master topic master topic Fast-forward
  • 42. topic basics stages branch merge remotes advanced master master, topic Fast-forward
  • 43. basics stages branch merge remotes advanced master topic master topic
  • 44. basics stages branch merge remotes advanced master topic master topic Recursive three-way
  • 45. basics stages branch merge remotes advanced master topic A merge commit with 2 parents Recursive three-way
  • 46. basics stages branch merge remotes advanced Conflicts
  • 47. basics stages branch merge remotes advanced master
  • 48. basics stages branch merge remotes advanced class Main { public static void main(String... args) { } } master
  • 49. basics stages branch merge remotes advanced class Main { public static void main(String... args) { } } master topic
  • 50. basics stages branch merge remotes advanced class Main { public static void main(String... args) { } } class Main { static int status = 0; public static void main(String... args) { System.exit(status); } } master topic
  • 51. basics stages branch merge remotes advanced class Main { public static void main(String... args) { System.exit(0); } } class Main { public static void main(String... args) { } } class Main { static int status = 0; public static void main(String... args) { System.exit(status); } } master topic
  • 52. basics stages branch merge remotes advanced class Main { public static void main(String... args) { System.exit(0); } } class Main { public static void main(String... args) { } } class Main { static int status = 0; public static void main(String... args) { System.exit(status); } } class Main { static int status = 0; public static void main(String... args) { <<<<<<< HEAD System.exit(0); ======= System.exit(status); >>>>>>> topic } } master topic
  • 53. basics stages branch merge remotes advanced
  • 54. basics stages branch merge remotes advanced master develop topic (features)
  • 55. basics stages branch remotes advanced master merge
  • 56. basics stages branch remotes advanced git branch develop master develop merge
  • 57. basics stages branch remotes advanced master develop merge
  • 58. basics stages branch remotes advanced master develop merge
  • 59. basics stages branch remotes advanced master develop feature git branch featureX merge
  • 60. basics stages branch remotes advanced master develop feature feature git branch featureY merge
  • 61. basics stages branch remotes advanced master develop feature feature git branch featureY merge
  • 62. basics stages branch remotes advanced master develop feature feature git merge featureX merge
  • 63. basics stages branch merge remotes advanced master develop feature feature git merge develop
  • 64. basics stages branch merge remotes advanced master develop feature feature version 1.0
  • 65. basics stages branch merge remotes advanced master develop feature feature git merge develop downmerge
  • 66. basics stages branch merge remotes advanced master develop feature feature version 2.0
  • 67. basics stages branch merge remotes advanced master develop feature feature
  • 68. basics stages branch merge remotes advanced
  • 69. basics stages branch merge remotes advanced working directory staging area repository
  • 70. basics stages branch merge remotes advanced working directory staging area local repository remote repository
  • 71. basics stages branch merge remotes advanced working directory staging area local repository remote repository working directory staging area local repository working directory staging area local repository developer developer developer
  • 72. basics stages branch merge remotes advanced working directory staging area local repository remote repository working directory staging area local repository working directory staging area local repository developer developer developer origin
  • 73. basics stages branch merge remotes advanced working directory staging area local repository remote repository
  • 74. basics stages branch merge remotes advanced working directory staging area local repository remote repository git add/mv/rm git commit git commit -a git reset <file> git checkout <branch>
  • 75. basics stages branch merge remotes advanced working directory staging area local repository remote repository git push git add/mv/rm git commit git commit -a git reset <file> git checkout <branch>
  • 76. basics stages branch merge remotes advanced working directory staging area local repository remote repository git push git fetch git add/mv/rm git commit git commit -a git reset <file> git checkout <branch>
  • 77. basics stages branch merge remotes advanced working directory staging area local repository remote repository git push git fetch git pull git add/mv/rm git commit git commit -a git reset <file> git checkout <branch>
  • 78. basics stages branch merge remotes advanced Subversion working directory
  • 79. basics stages branch merge remotes advanced Subversion working directory remote repository
  • 80. basics stages branch merge remotes advanced commit Subversion working directory remote repository
  • 81. basics stages branch merge remotes advanced updatecommit Subversion working directory remote repository
  • 82. basics stages branch merge remotes advanced updatecommit working directory Subversion Git working directory remote repository
  • 83. basics stages branch merge remotes advanced updatecommit local repository working directory Subversion Git working directory remote repository
  • 84. basics stages branch merge remotes advanced updatecommit local repository working directory remote repository Subversion Git working directory remote repository
  • 85. basics stages branch merge remotes advanced Distribution models
  • 86. basics stages branch merge remotes advanced Distribution models Centralized workflow origin
  • 87. basics stages branch merge remotes advanced Distribution models Centralized workflow origin GitHub Forking/Pull Request dictator
  • 88. basics stages branch merge remotes advanced Distribution models Centralized workflow origin GitHub Forking/Pull Request upstream dictator developers fork origin
  • 89. basics stages branch merge remotes advanced Distribution models Centralized workflow origin GitHub Forking/Pull Request upstream dictator developers fork origin
  • 90. basics stages branch merge remotes advanced Distribution models Centralized workflow origin GitHub Forking/Pull Request Pull request upstream dictator developers origin fork
  • 91. basics stages branch merge remotes advanced Distribution models Centralized workflow origin GitHub Forking/Pull Request Pull request upstream dictator developers origin fork Many others
  • 92. basics stages branch merge remotes advanced Managing remotes $ git remote -v origin [email protected]:thrau/openengsb-framework.git (fetch) origin [email protected]:thrau/openengsb-framework.git (push) upstream [email protected]:openengsb/openengsb-framework.git (fetch) upstream [email protected]:openengsb/openengsb-framework.git (push) $ git remote add <name> <url> $ git remote rm <name>
  • 93. basics stages branch merge remotes advanced Remote tracking branches $ git branch -a
  • 94. basics stages branch merge remotes advanced Remote tracking branches $ git branch -a * master my-local-feature remotes/origin/master
  • 95. basics stages branch merge remotes advanced Remote tracking branches $ git branch -a * master my-local-feature remotes/origin/master originlocal master master, origin/master
  • 96. basics stages branch merge remotes advanced Remote tracking branches $ git branch -a * master my-local-feature remotes/origin/master originlocal master master, origin/master
  • 97. basics stages branch merge remotes advanced Remote tracking branches $ git branch -a * master my-local-feature remotes/origin/master master origin/master originlocal master
  • 98. basics stages branch merge remotes advanced Remote tracking branches $ git push master, origin/master originlocal master
  • 99. basics stages branch merge remotes advanced Delete remote branches $ git push origin :branchname
  • 100. basics stages branch merge remotes advanced Delete local tracking branches $ git fetch origin --prune
  • 101. basics stages branch merge remotes advanced Dealing with remote conflicts
  • 102. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master
  • 103. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master master, origin/master originlocal master
  • 104. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master To ssh://thomas@localhost/home/thomas/git-remote ! [rejected] HEAD -> master (non-fast-forward) error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 105. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master To ssh://thomas@localhost/home/thomas/git-remote ! [rejected] HEAD -> master (non-fast-forward) error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ git pull origin master
  • 106. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master To ssh://thomas@localhost/home/thomas/git-remote ! [rejected] HEAD -> master (non-fast-forward) error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ git pull origin master … fix merge conflicts ...
  • 107. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master To ssh://thomas@localhost/home/thomas/git-remote ! [rejected] HEAD -> master (non-fast-forward) error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ git pull origin master … fix merge conflicts ... $ git commit -am "Merge remote branch 'master'" $ git push origin master
  • 108. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master To ssh://thomas@localhost/home/thomas/git-remote ! [rejected] HEAD -> master (non-fast-forward) error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ git pull origin master … fix merge conflicts ... $ git commit -am "Merge remote branch 'develop'" $ git push origin master Produces a merge commit
  • 109. basics stages branch merge remotes advanced Dealing with remote conflicts $ git push origin master To ssh://thomas@localhost/home/thomas/git-remote ! [rejected] HEAD -> master (non-fast-forward) error: failed to push some refs to 'ssh://thomas@localhost/home/thomas/git-remote' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ git pull --rebase origin master … fix merge conflicts ... $ git rebase --continue repeat $ git push origin master Rewrites the history.
  • 110. basics stages branch merge remotes advanced
  • 111. basics stages branch merge remotes advanced
  • 112. basics stages branch merge remotes advanced Rewriting history
  • 113. basics stages branch merge remotes advanced Rewriting history $ git rebase master Rebase the current branch on to the tip of a different one
  • 114. basics stages branch merge remotes advanced Rewriting history master topic master topic $ git rebase master Rebase the current branch on to the tip of a different one
  • 115. basics stages branch merge remotes advanced Rewriting history master topic “base” $ git rebase master Rebase the current branch on to the tip of a different one
  • 116. basics stages branch merge remotes advanced Rewriting history master topic “base” $ git rebase master Rebase the current branch on to the tip of a different one
  • 117. basics stages branch merge remotes advanced Rewriting history master topic $ git rebase master Rebase the current branch on to the tip of a different one
  • 118. basics stages branch merge remotes advanced Rewriting history master topic $ git rebase master Rebase the current branch on to the tip of a different one
  • 119. basics stages branch merge remotes advanced Rewriting history master topic “base” * * ** * new commits $ git rebase master Rebase the current branch on to the tip of a different one
  • 120. basics stages branch merge remotes advanced Rewriting history master topic * * ** Avoid changing published histories! $ git rebase master Rebase the current branch on to the tip of a different one
  • 121. basics stages branch merge remotes advanced Ups, I forgot something
  • 122. basics stages branch merge remotes advanced Ups, I forgot something $ git commit --amend -a Add all your current changes to the previous commit
  • 123. basics stages branch merge remotes advanced Ups, I forgot something $ git commit --amend -a $ git commit --amend -m "new commit message" Reword the last commit Add all your current changes to the previous commit
  • 124. basics stages branch merge remotes advanced Ups, I forgot something $ git commit --amend -a Add all your current changes to the previous commit $ git commit --amend -m "new commit message" Reword the last commit Avoid changing published histories!
  • 125. basics stages branch merge remotes advanced Pushing a rewritten history $ git push --force origin <branch> Danger zone! Overwrites the remote history with your local one. Remote commits may get lost!
  • 126. basics stages branch merge remotes advanced When that merge came in like a wrecking ball $ git merge --abort $ git rebase --abort Abort an initiated merge or rebase
  • 127. basics stages branch merge remotes advanced Git tag $ git tag Show all tags $ git tag -a v2.0 Tag the current commit with an annotation Tag (mark) important points in the commit history, e.g. when a working version is released $ git push origin --tags Push tags to the remote
  • 128. basics stages branch merge remotes advanced Ignoring files Create a file in your repository (and add & commit it) named .gitignore, containing paths and rules that tell git which files to ignore. # Maven files target/ bin/ # Eclipse project files .project .classpath .settings # Mac OS .DS_Store # IntelliJ IDEA files *.iml *.ipr *.iws .idea # backup-files *~
  • 129. basics stages branch merge remotes advanced Writing good commit messages
  • 130. basics stages branch merge remotes advanced Writing *bad* commit messages
  • 131. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix”
  • 132. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix” “:(:(“
  • 133. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix” “:(:(“ “changes”
  • 134. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix” “:(:(“ “changes” “it works!”
  • 135. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix” “:(:(“ “changes” “it works!” “final commit”
  • 136. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix” “:(:(“ “changes” “it works!” “final commit” “Testing in progress ;-)”
  • 137. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix” “:(:(“ “changes” “it works!” “final commit” “Testing in progress ;-)” “TODO: write meaningful commit message”
  • 138. basics stages branch merge remotes advanced Writing *bad* commit messages ”fix” “:(:(“ “changes” “it works!” “final commit” “Testing in progress ;-)” “TODO: write meaningful commit message” “Your commit is writing checks your merge can't cash”
  • 139. basics stages branch merge remotes advanced Writing good commit messages Write commit messages as if you're giving commands to the codebase
  • 140. basics stages branch merge remotes advanced Writing good commit messages Write commit messages as if you're giving commands to the codebase “Add DAO interfaces for Entities“
  • 141. basics stages branch merge remotes advanced Writing good commit messages Write commit messages as if you're giving commands to the codebase “Add DAO interfaces for Entities“ “Implement basic version of AddressDAO”
  • 142. basics stages branch merge remotes advanced Writing good commit messages Write commit messages as if you're giving commands to the codebase “Add DAO interfaces for Entities“ “Implement basic version of AddressDAO” “Fix bug in delete method of UserDAO” “Move package security to at.ac.tuwien.service” “Add generated fxml files for UI”
  • 143. basics stages branch merge remotes advanced
  • 144. basics stages branch merge remotes advanced
  • 145. Other great tutorials ● Official Git Documentation http://git-scm.com/doc ● TryGit – An interactive Git tutorial http://try.github.io ● Git Immersion http://gitimmersion.com/ ● Atlassian Git Tutorials https://www.atlassian.com/git ● Git Cheatsheet – Command categorisation http://ndpsoftware.com/git-cheatsheet.html ● LearnGitBranching http://pcottle.github.io/learnGitBranching
  • 146. Further reading ● A successful Git branching model http://nvie.com/posts/a-successful-git-branching-model/ ● Changing history, or How to Git pretty http://justinhileman.info/article/changing-history ● Reset Demystified http://git-scm.com/blog/2011/07/11/reset.html ● Avoiding Git Disasters: A Gory Story http://randyfay.com/node/89 ● A Rebase Workflow for Git http://randyfay.com/node/91
  • 148. fin Thanks for listening - Enjoy git! Feedback appreciated [email protected]