Академический Документы
Профессиональный Документы
Культура Документы
to Git
References
http://gitref.org
http://try.github.io
http://git-scm.com/doc
http://stackoverflow.com
distributed git
remote repository
remote repository
local repository
remote repository
git clone
git pull
git remote
local repository
remote repository
git clone
git pull
git remote
git push
local repository
which means
everything is fast
every clone is a backup
work offline
no network needed
performing a diff
viewing file history
committing changes
no network needed
merging branches
obtaining other revisions of a file
switching branches
subversion-style workflow
shared
repository
public
subversion-style workflow
shared
repository
developer
developer
private
public
developer
subversion-style workflow
shared
repository
developer
developer
private
public
developer
public
private
blessed
repository
public
private
blessed
repository
public
private
developer
public
developer
public
blessed
repository
public
private
integration
manager
developer
public
developer
public
blessed
repository
developer
public
developer
public
developer
private
developer
private
public
private
integration
manager
developer
public
developer
public
developer
private
developer
private
public
private
integration
manager
developer
public
developer
public
developer
private
developer
private
public
private
integration
manager
developer
public
developer
public
developer
private
developer
private
public
private
integration
manager
developer
public
developer
public
developer
private
developer
private
public
private
integration
manager
before starting
colors in git
$ git config --global color.ui true
colors in git
$ git config --global color.ui true
colors in git
$ git config --global color.ui true
help
$ git help command
topic branches
topic branches
topic branches
production
code
production
code
merge
production
code
merge
disposable experimentation
master
develop
topic branches
disposable experimentation
master
develop
topic branches
disposable experimentation
master
develop
topic branches
disposable experimentation
master
develop
topic branches
git init
$ mkdir xpto-local
$ mkdir xpto-local
$ cd xpto-local
$ mkdir xpto-local
$ cd xpto-local
$ git init
$ mkdir xpto-local
$ cd xpto-local
$ git init
Initialized empty Git repository in /tmp/
mygitproject/.git/
$ mkdir xpto-local
$ cd xpto-local
$ git init
Initialized empty Git repository in /tmp/
mygitproject/.git/
$ ls -a
$ mkdir xpto-local
$ cd xpto-local
$ git init
Initialized empty Git repository in /tmp/
mygitproject/.git/
$ ls -a
. ..
.git
.
!"" .git
#"" HEAD
#"" config
#"" description
#"" hooks
$ #"" applypatch-msg.sample
$ #"" commit-msg.sample
$ #"" ...
$ #"" prepare-commit-msg.sample
$ !"" update.sample
#"" info
$ !"" exclude
#"" objects
$ #"" info
$ !"" pack
!"" refs
#"" heads
!"" tags
9 directories, 13 files
$ tree -a
.
!"" .git
#"" HEAD
#"" config
#"" description
#"" hooks
$ #"" applypatch-msg.sample
$ #"" commit-msg.sample
$ #"" ...
$ #"" prepare-commit-msg.sample
$ !"" update.sample
#"" info
$ !"" exclude
#"" objects
$ #"" info
$ !"" pack
!"" refs
#"" heads
!"" tags
9 directories, 13 files
$ tree -a
$ touch HelloWorld.java
.
!"" .git
#"" HEAD
#"" config
#"" description
#"" hooks
$ #"" applypatch-msg.sample
$ #"" commit-msg.sample
$ #"" ...
$ #"" prepare-commit-msg.sample
$ !"" update.sample
#"" info
$ !"" exclude
#"" objects
$ #"" info
$ !"" pack
!"" refs
#"" heads
!"" tags
9 directories, 13 files
$ tree -a
$ touch HelloWorld.java
$ git add .
.
!"" .git
#"" HEAD
#"" config
#"" description
#"" hooks
$ #"" applypatch-msg.sample
$ #"" commit-msg.sample
$ #"" ...
$ #"" prepare-commit-msg.sample
$ !"" update.sample
#"" info
$ !"" exclude
#"" objects
$ #"" info
$ !"" pack
!"" refs
#"" heads
!"" tags
9 directories, 13 files
$
$
$
$
tree -a
touch HelloWorld.java
git add .
git commit -m initial commit
.
#""
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
$
!""
$ tree -a
.git
$ touch HelloWorld.java
#"" ...
#"" config
$ git add .
#"" description
$ git commit -m initial
#"" hooks
$
#"" applypatch-msg.sample
$ tree -a
$
#"" commit-msg.sample
$
#"" ...
$
#"" pre-rebase.sample
$
#"" prepare-commit-msg.sample
$
!"" update.sample
#"" index
#"" info
$
!"" exclude
#"" logs
$
#"" HEAD
$
!"" refs
$
!"" heads
$
!"" master
#"" objects
$
#"" 66/4d5c28a7d49e6381d3e26d8b1e8d94576fd924
$
#"" 70/21125e13a868aadc609aad3ff2a7e325a2b986
$
#"" e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
$
#"" info
$
!"" pack
!"" refs
#"" heads
$
!"" master
!"" tags
HelloWorld.java
15 directories, 23 files
commit
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
git clone
..
.git
HelloWorld.java
$ cat .git/config
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
url = git@10.224.200.6:projects/gitworkshop.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
staging area
staging area
working directory
staging area
repository
working directory
git add
staging area
repository
working directory
git add
staging area
git commit
repository
working directory
staging area
repository
git commit -a
working directory
staging area
repository
git commit -a
working directory
staging area
repository
git commit -a
working directory
staging area
git commit -a
repository
working directory
staging area
git commit -a
!
repository
basic snapshoting
git status
git diff
git add
git commit
def self.hello
puts "hello world"
puts "hola mundo"
end
end
Edit files
Eclipse/Sublime/vim/emacs/etc
Edit files
Eclipse/Sublime/vim/emacs/etc
Edit files
Eclipse/Sublime/vim/emacs/etc
Edit files
Eclipse/Sublime/vim/emacs/etc
or
1
Edit files
Eclipse/Sublime/vim/emacs/etc
or
1
Edit files
Eclipse/Sublime/vim/emacs/etc
or
1
Edit files
Eclipse/Sublime/vim/emacs/etc
git reset
Be careful
git reset --hard unstages files AND undoes any changes in the
working directory since last commit
$
#
#
#
#
#
#
git reset --hard unstages files AND undoes any changes in the
working directory since last commit
git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified:
README
git reset --hard unstages files AND undoes any changes in the
working directory since last commit
$ git status
# On branch master
# Changes to be committed:
#
(use "git reset HEAD <file>..." to unstage)
#
# modified:
README
#
# 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
#
git reset --hard unstages files AND undoes any changes in the
working directory since last commit
$ git status
# On branch master
# Changes to be committed:
#
(use "git reset HEAD <file>..." to unstage)
#
# modified:
README
#
# 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
#
$ git reset --hard HEAD
HEAD is now at 5857ac1 hello with a flower
git reset --hard unstages files AND undoes any changes in the
working directory since last commit
$ git status
# On branch master
# Changes to be committed:
#
(use "git reset HEAD <file>..." to unstage)
#
# modified:
README
#
# 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
#
$ git reset --hard HEAD
HEAD is now at 5857ac1 hello with a flower
$ git status
# On branch master
nothing to commit (working directory clean)
git rm
git mv
git rm --cached orig
mv orig new
git add new
git mv
git rm --cached orig
mv orig new
git add new
git stash
$ git status -s
M hello.rb
$ git status -s
M hello.rb
$ git stash
Saved working directory and index state WIP on master: 5857ac1
hello with a flower
HEAD is now at 5857ac1 hello with a flower
$ git status -s
M hello.rb
$ git stash
Saved working directory and index state WIP on master: 5857ac1
hello with a flower
HEAD is now at 5857ac1 hello with a flower
$ git status
# On branch master
nothing to commit (working directory clean)
$ git status -s
M hello.rb
$ git stash
Saved working directory and index state WIP on master: 5857ac1
hello with a flower
HEAD is now at 5857ac1 hello with a flower
$ git status
# On branch master
nothing to commit (working directory clean)
git stash apply grabs the item from the stash list
and apply to current working directory
git stash apply grabs the item from the stash list
and apply to current working directory
$ git stash apply
git stash apply grabs the item from the stash list
and apply to current working directory
$ git stash apply
# 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:
hello.rb
#
no changes added to commit (use "git add" and/or "git commit -a")
git tag
git log
git branch
git checkout
$ git branch
* master
$ git branch
* master
$ git branch
* master
C0
master
C0
C1
master
develop
C0
C1
master
$
$
$
$
echo C0 >>
echo C1 >>
git checkout
echo C2 >>
develop
C0
C1
master
C2
$
$
$
$
$
echo C0 >>
echo C1 >>
git checkout
echo C2 >>
echo C3 >>
arq.txt &&
arq.txt &&
-b develop
arq.txt &&
arq.txt &&
develop
C0
C1
master
C2
C3
git commit -a
git commit -a
git commit -a
git commit -a
$
$
$
$
$
$
echo C0 >>
echo C1 >>
git checkout
echo C2 >>
echo C3 >>
git checkout
feature/f1
develop
C0
C1
master
C2
C3
commit -a
commit -a
commit -a
commit -a
$ ls
README
hello.rb
$ ls
README
hello.rb
$ echo 'test content' > test.txt
$ ls
README
hello.rb
$ echo 'test content' > test.txt
$ echo 'more content' > more.txt
$ ls
README
hello.rb
$ echo 'test content' > test.txt
$ echo 'more content' > more.txt
$ git add *.txt
$ ls
README
hello.rb
$ echo 'test content' > test.txt
$ echo 'more content' > more.txt
$ git add *.txt
$ git commit -m 'added two files'
[master 8bd6d8b] added two files
2 files changed, 2 insertions(+),
0 deletions(-)
create mode 100644 more.txt
create mode 100644 test.txt
$ ls
README
hello.rb
$ echo 'test content' > test.txt
$ echo 'more content' > more.txt
$ git add *.txt
$ git commit -m 'added two files'
[master 8bd6d8b] added two files
2 files changed, 2 insertions(+),
0 deletions(-)
create mode 100644 more.txt
create mode 100644 test.txt
$ ls
README
hello.rb more.txt test.txt
$ ls
README
hello.rb
$ echo 'test content' > test.txt
$ echo 'more content' > more.txt
$ git add *.txt
$ git commit -m 'added two files'
[master 8bd6d8b] added two files
2 files changed, 2 insertions(+),
0 deletions(-)
create mode 100644 more.txt
create mode 100644 test.txt
$ ls
README
hello.rb more.txt test.txt
$ git checkout testing
Switched to branch 'testing'
$ ls
README
hello.rb
$ echo 'test content' > test.txt
$ echo 'more content' > more.txt
$ git add *.txt
$ git commit -m 'added two files'
[master 8bd6d8b] added two files
2 files changed, 2 insertions(+),
0 deletions(-)
create mode 100644 more.txt
create mode 100644 test.txt
$ ls
README
hello.rb more.txt test.txt
$ git checkout testing
Switched to branch 'testing'
$ ls
README
hello.rb
git merge
feature/f1
C0
C1
master
C2
C3
develop
feature/f1
C0
C1
master
C2
C3
develop
C4
feature/f1
C0
C1
master
C2
C3
develop
C4
C5
feature/f1
C0
C1
master
C2
C3
develop
C4
C5
C6
$
$
$
$
echo C4 >>
echo C5 >>
echo C6 >>
git checkout
feature/f1
C0
C1
master
C2
C3
develop
C4
C5
C6
$
$
$
$
$
feature/f1
C0
C1
master
C2
C3
C4
C5
C6
develop
feature/f1
C4
C0
C1
master
C2
C3
develop
C5
C6
feature/f1
C4
C0
C1
master
C2
C3
C4
develop
C5
C6
feature/f1
C4
C0
C1
master
C2
C3
C4
C5
C6
C7
develop
$
$
$
$
$
git
git
git
vim
git
checkout -b change_class
mv HelloWorld.java HiWorld.java
status
HelloWorld.java (Change the class name to HiWorld)
commit -am Changed class name
$
$
$
$
$
git
git
git
vim
git
checkout -b change_class
mv HelloWorld.java HiWorld.java
status
HelloWorld.java (Change the class name to HiWorld)
commit -am Changed class name
$
$
$
$
$
git
git
git
vim
git
checkout -b change_class
mv HelloWorld.java HiWorld.java
status
HelloWorld.java (Change the class name to HiWorld)
commit -am Changed class name
resolving conflicts
Conflicts mean parallel evolutions of the same content
common
ancestor
Conflicts!
Conflicts!
Conflicts!
git rebase
feature/f1
C5
C0
C1
master
C2
C3
C4
develop
feature/f1
C5
C0
C1
master
C2
C3
C4
develop
feature/f1
C0
C1
master
C2
C3
C4
develop
C5
feature/f1
C0
C1
master
C2
C3
C4
develop
C5
$
$
$
$
git
git
git
git
checkout feature/f1
rebase develop
checkout develop
merge feature/f1
feature/f1
C0
C1
master
C2
C3
C4
C5
develop
git remote
git fetch
git pull
git push
remote alias
$ git push origin develop
remote alias
$ git push origin develop
branch
developer 1 (local)
shared repository
developer 2 (local)
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
developer 1 (local)
clone (state1)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
state1
commit
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
clone (state1)
state1
commit
commit
state1
commit
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
clone (state1)
state1
commit
commit
state1
commit
commit
state2
push (state2)
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
clone (state1)
state1
commit
commit
state1
commit
commit
state2
push (state2)
commit
state2
commit
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
clone (state1)
state1
commit
commit
state1
commit
commit
state2
push (state2)
commit
state2
commit
commit
state2
commit
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
clone (state1)
state1
commit
commit
state1
commit
commit
state2
push (state2)
commit
state2
commit
commit
state2
commit
commit
state3
push (state3)
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
clone (state1)
state1
commit
commit
state1
commit
commit
state2
push (state2)
commit
state2
commit
commit
state2
commit
commit
state3
push (state3)
push
state3
developer 1 (local)
shared repository
developer 2 (local)
state0
clone (state0)
state0
commit
state0
commit
state1
push (state1)
clone (state1)
state1
commit
commit
state1
commit
commit
state2
push (state2)
commit
state2
commit
commit
state2
commit
commit
state3
push (state3)
push
state3
rejected!
be careful!
be careful!
useful things
aliases
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.lol log --oneline --graph --decorate
git blame
git bisect
git revert
git show
git diff
git request-pull