33
GIT GOOD PRACTICES Rodolfo Spalenza @rodolfospalenza rodolfospalenza

GIT - GOOD PRACTICES

Embed Size (px)

Citation preview

Page 1: GIT - GOOD PRACTICES

GIT

GOOD PRACTICES  

Rodolfo  Spalenza    

@rodolfospalenza    

rodolfospalenza  

Page 2: GIT - GOOD PRACTICES

#1 FORK  

Page 3: GIT - GOOD PRACTICES

#1 FORK  

Page 4: GIT - GOOD PRACTICES

#2 CLONE  

~ $ git clone [email protected]:rodolfospalenza/ancestry.git Cloning into 'ancestry'... remote: Counting objects: 485, done. remote: Compressing objects: 100% (241/241), done. Receiving objects: 99% (481/485), 956.00 KiB | 27 KiB/s remote: Total 485 (delta 282), reused 411 (delta 222) Receiving objects: 100% (485/485), 8.29 MiB | 34 KiB/s, done. Resolving deltas: 100% (282/282), done.

Page 5: GIT - GOOD PRACTICES

#3 REMOTE  

~/ancestry [master] $ git remote –v origin [email protected]:rodolfospalenza/ancestry.git (fetch) origin [email protected]:rodolfospalenza/ancestry.git (push)

~/ancestry [master] $ git remote add upstream git://github.com/stefankroes/ancestry.git

~/ancestry [master] $ git remote -v origin [email protected]:rodolfospalenza/ancestry.git (fetch) origin [email protected]:rodolfospalenza/ancestry.git (push) upstream git://github.com/stefankroes/ancestry.git (fetch) upstream git://github.com/stefankroes/ancestry.git (push)

Page 6: GIT - GOOD PRACTICES

#4 FETCH  

~/ancestry [master] $ git fetch origin master From github.com:rodolfospalenza/ancestry * branch master -> FETCH_HEAD

~/ancestry [master] $ git fetch upstream master From git://github.com/stefankroes/ancestry * branch master -> FETCH_HEAD

Page 7: GIT - GOOD PRACTICES

#5 REPOSITORIES  

LOCAL   ORIGIN   UPSTREAM  

Page 8: GIT - GOOD PRACTICES

#6 COMMIT  

~/ancestry [master] $ touch new_file.rb ~/ancestry [master] $ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # new_file.rb nothing added to commit but untracked files present (use "git add" to track)

Page 9: GIT - GOOD PRACTICES

#6 COMMIT  

~/ancestry [master] $ git add . ~/ancestry [master] $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: new_file.rb #

~/ancestry [master] $ git commit -m "New file." [master 248a8a4] New file. 0 files changed create mode 100644 new_file.rb

Page 10: GIT - GOOD PRACTICES

#7 REBASE  

~/ancestry [master] $ git fetch upstream From git://github.com/stefankroes/ancestry * [new branch] 1-3-stable -> upstream/1-3-stable * [new branch] gh-pages -> upstream/gh-pages * [new branch] master -> upstream/master * [new branch] rails3 -> upstream/rails3 From git://github.com/stefankroes/ancestry * branch master -> FETCH_HEAD

~/ancestry [master] $ git rebase upstream/master master Already on 'master' Current branch master is up to date.

Page 11: GIT - GOOD PRACTICES

#8 PUSH  ~/ancestry [master] $ git push origin master Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 284 bytes, done. Total 3 (delta 1), reused 0 (delta 0) To [email protected]:rodolfospalenza/ancestry.git 39f00ab..248a8a4 master -> master

Page 12: GIT - GOOD PRACTICES

#9 PULL REQUEST  

Page 13: GIT - GOOD PRACTICES

#9 PULL REQUEST  

Page 14: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  

~/ancestry [master] $ git log --graph * commit bbf1e7e177f0a86f635c41b6181f1694a71492ce | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 21:52:47 2012 -0200 | | Add new file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <[email protected]> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!

USER 01  

Page 15: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  USER 01  

~/ancestry [master] $ git push origin master Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 614 bytes, done. Total 3 (delta 1), reused 0 (delta 0) To [email protected]:rodolfospalenza/ancestry.git 39f00ab..bbf1e7e master -> master

Page 16: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  

~/ancestry [master] $ git log --graph * commit 5310b92074cde08673a622a476ee95edd98cd387 | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 21:52:47 2012 -0200 | | Add old file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <[email protected]> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!

USER 02  

Page 17: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  USER 02  

~/ancestry [master] $ git push origin master To [email protected]:rodolfospalenza/ancestry.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '[email protected]:rodolfospalenza/ancestry.git' 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.

Page 18: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  USER 02  

~/ancestry [master] $ git pull origin master remote: Counting objects: 4, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 3 (delta 1) Unpacking objects: 100% (3/3), done. From github.com:rodolfospalenza/ancestry * branch master -> FETCH_HEAD Merge made by the 'recursive' strategy. new_file | 1 + 1 file changed, 1 insertion(+) create mode 100644 new_file

Page 19: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  USER 02  

~/ancestry [master] $ git log --graph * commit 7a85d5c39575dec335a86ed936c2c6a949b51de0 |\ Merge: 5310b92 bbf1e7e | | Author: Rodolfo Spalenza <[email protected]> | | Date: Tue Dec 11 22:06:49 2012 -0200 | | | | Merge branch 'master' of github.com:rodolfospalenza/ancestry | | | * commit bbf1e7e177f0a86f635c41b6181f1694a71492ce | | Author: Rodolfo Spalenza <[email protected]> | | Date: Tue Dec 11 21:52:47 2012 -0200 | | | | Add new file. | | * | commit 5310b92074cde08673a622a476ee95edd98cd387 |/ Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:02:54 2012 -0200 | | Add old file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <[email protected]> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!

Page 20: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  

COMMIT  USER  02  

MERGE  

COMMIT  USER  01  

Page 21: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  

Page 22: GIT - GOOD PRACTICES

#10 REBASE VS. PULL  

~/ancestry [master] $ git fetch origin From github.com:rodolfospalenza/ancestry 39f00ab..bbf1e7e master -> origin/master

~/ancestry [master] $ git rebase origin/master master First, rewinding head to replay your work on top of it... Applying: Add old file.

USER 02  

Page 23: GIT - GOOD PRACTICES

USER 02  #10 REBASE VS. PULL  

~/ancestry [master] $ git log --graph * commit c765729377be06ecba78e3dd110a66f348699475 | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. | * commit bbf1e7e177f0a86f635c41b6181f1694a71492ce | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 21:52:47 2012 -0200 | | Add new file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <[email protected]> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!

Page 24: GIT - GOOD PRACTICES

USER 02  #10 REBASE VS. PULL  

~/ancestry [master] $ git push origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 250 bytes, done. Total 2 (delta 1), reused 0 (delta 0) To [email protected]:rodolfospalenza/ancestry.git bbf1e7e..c765729 master -> master

Page 25: GIT - GOOD PRACTICES

#11 AMENDED COMMIT  

~/ancestry [master] $ git log --graph * commit c765729377be06ecba78e3dd110a66f348699475 | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. |

~/ancestry [master] $ git add . ~/ancestry [master] $ git commit --amend

Page 26: GIT - GOOD PRACTICES

#11 AMENDED COMMIT  

1 Add old file. 2 3 # Please enter the commit message for your changes. Lines starting 4 # with '#' will be ignored, and an empty message aborts the commit. 5 # On branch master 6 # Changes to be committed: 7 # (use "git reset HEAD^1 <file>..." to unstage) 8 # 9 # new file: old_file 10 #

Page 27: GIT - GOOD PRACTICES

#11 AMENDED COMMIT  

~/ancestry [master] $ git log --graph * commit e1dbf27ef62cef023437a710f5101dbf762efbef | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. |

Page 28: GIT - GOOD PRACTICES

#12 INTERACTIVE REBASE  

~/ancestry [master] $ git rebase –i HEAD~3

~/ancestry [master] $ git log --graph * commit 3c8464613ce94ff78372ce5c0fbf049d2fa5524e | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:51:10 2012 -0200 | | Add example file. | * commit e1dbf27ef62cef023437a710f5101dbf762efbef | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. |

Page 29: GIT - GOOD PRACTICES

#12 INTERACTIVE REBASE  

1 pick bbf1e7e Add new file. 2 r e1dbf27 Add old file. 3 f 3c84646 Add example file. 4 5 # Rebase 39f00ab..3c84646 onto 39f00ab 6 # 7 # Commands: 8 # p, pick = use commit 9 # r, reword = use commit, but edit the commit message 10 # e, edit = use commit, but stop for amending 11 # s, squash = use commit, but meld into previous commit 12 # f, fixup = like "squash", but discard this commit's log message 13 # x, exec = run command (the rest of the line) using shell 14 # 15 # These lines can be re-ordered; they are executed from top to bottom. 16 # 17 # If you remove a line here THAT COMMIT WILL BE LOST. 18 # However, if you remove everything, the rebase will be aborted. 19 # 20 # Note that empty commits are commented out

Page 30: GIT - GOOD PRACTICES

#12 INTERACTIVE REBASE  

1 Add old file with rebase. 2 3 # Please enter the commit message for your changes. Lines starting 4 # with '#' will be ignored, and an empty message aborts the commit. 5 # Not currently on any branch. 6 # You are currently editing a commit during a rebase. 7 8 # Changes to be committed: 9 # (use "git reset HEAD^1 <file>..." to unstage) 10 # 11 # new file: old_file 12 #

Page 31: GIT - GOOD PRACTICES

#12 INTERACTIVE REBASE  

~/ancestry [master] $ git rebase –i HEAD~3 [detached HEAD e2afa36] Add old file with rebase. 1 file changed, 3 insertions(+) create mode 100644 old_file [detached HEAD 952118d] Add old file with rebase. 2 files changed, 4 insertions(+) create mode 100644 example create mode 100644 old_file Successfully rebased and updated refs/heads/master.

Page 32: GIT - GOOD PRACTICES

~/ancestry [master] $ git log --graph * commit 952118d7fb53a33040f50707053ee1499f0728b9 | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file with rebase. | * commit Tue Dec 11 21:52:47 2012 -0200 | Author: Rodolfo Spalenza <[email protected]> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add new file. |

#12 INTERACTIVE REBASE  

Page 33: GIT - GOOD PRACTICES

REFERENCES  h<ps://help.github.com/arGcles/fork-­‐a-­‐repo  

h<p://git-­‐scm.com/book/en/Git-­‐Branching-­‐Rebasing  

h<p://learn.github.com/p/rebasing.html  

h<p://blip.tv/akitaonrails/screencast-­‐come-­‐ando-­‐com-­‐git-­‐6074964