GIT - GOOD PRACTICES

  • 842 views
Uploaded on

 

More in: Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
842
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
11
Comments
2
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. GITGOOD PRACTICES   Rodolfo  Spalenza     @rodolfospalenza     rodolfospalenza  
  • 2. #1 FORK  
  • 3. #1 FORK  
  • 4. #2 CLONE   ~ $ git clone git@github.com: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.
  • 5. #3 REMOTE   ~/ancestry [master] $ git remote –v origin git@github.com:rodolfospalenza/ancestry.git (fetch) origin git@github.com:rodolfospalenza/ancestry.git (push) ~/ancestry [master] $ git remote add upstream git:// github.com/stefankroes/ancestry.git ~/ancestry [master] $ git remote -v origin git@github.com:rodolfospalenza/ancestry.git (fetch) origin git@github.com:rodolfospalenza/ancestry.git (push) upstream git://github.com/stefankroes/ancestry.git (fetch) upstream git://github.com/stefankroes/ancestry.git (push)
  • 6. #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
  • 7. #5 REPOSITORIES   LOCAL   ORIGIN   UPSTREAM  
  • 8. #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)
  • 9. #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
  • 10. #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.
  • 11. #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 git@github.com:rodolfospalenza/ancestry.git 39f00ab..248a8a4 master -> master
  • 12. #9 PULL REQUEST  
  • 13. #9 PULL REQUEST  
  • 14. #10 REBASE VS. PULL   USER 01   ~/ancestry [master] $ git log --graph * commit bbf1e7e177f0a86f635c41b6181f1694a71492ce | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 21:52:47 2012 -0200 | | Add new file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <s.f.henzen@nedforce.nl> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!
  • 15. #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 git@github.com:rodolfospalenza/ancestry.git 39f00ab..bbf1e7e master -> master
  • 16. #10 REBASE VS. PULL   USER 02   ~/ancestry [master] $ git log --graph * commit 5310b92074cde08673a622a476ee95edd98cd387 | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 21:52:47 2012 -0200 | | Add old file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <s.f.henzen@nedforce.nl> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!
  • 17. #10 REBASE VS. PULL   USER 02   ~/ancestry [master] $ git push origin master To git@github.com:rodolfospalenza/ancestry.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to git@github.com: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.
  • 18. #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
  • 19. #10 REBASE VS. PULL   USER 02   ~/ancestry [master] $ git log --graph * commit 7a85d5c39575dec335a86ed936c2c6a949b51de0 | Merge: 5310b92 bbf1e7e | | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | | Date: Tue Dec 11 22:06:49 2012 -0200 | | | | Merge branch master of github.com:rodolfospalenza/ancestry | | | * commit bbf1e7e177f0a86f635c41b6181f1694a71492ce | | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | | Date: Tue Dec 11 21:52:47 2012 -0200 | | | | Add new file. | | * | commit 5310b92074cde08673a622a476ee95edd98cd387 |/ Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 22:02:54 2012 -0200 | | Add old file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <s.f.henzen@nedforce.nl> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!
  • 20. #10 REBASE VS. PULL   MERGE   COMMIT  USER  01   COMMIT  USER  02  
  • 21. #10 REBASE VS. PULL  
  • 22. #10 REBASE VS. PULL   USER 02   ~/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.
  • 23. #10 REBASE VS. PULL   USER 02   ~/ancestry [master] $ git log --graph * commit c765729377be06ecba78e3dd110a66f348699475 | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. | * commit bbf1e7e177f0a86f635c41b6181f1694a71492ce | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 21:52:47 2012 -0200 | | Add new file. | * commit 39f00abbbca1e6e90b1a268e918342b6950812c5 | Author: Stefan Henzen <s.f.henzen@nedforce.nl> | Date: Fri Jun 29 14:50:18 2012 +0200 | | fix readme, small fix in restore_ancestry_integrity!
  • 24. #10 REBASE VS. PULL   USER 02   ~/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 git@github.com:rodolfospalenza/ancestry.git bbf1e7e..c765729 master -> master
  • 25. #11 AMENDED COMMIT   ~/ancestry [master] $ git log --graph * commit c765729377be06ecba78e3dd110a66f348699475 | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. | ~/ancestry [master] $ git add . ~/ancestry [master] $ git commit --amend
  • 26. #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 #
  • 27. #11 AMENDED COMMIT   ~/ancestry [master] $ git log --graph * commit e1dbf27ef62cef023437a710f5101dbf762efbef | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. |
  • 28. #12 INTERACTIVE REBASE   ~/ancestry [master] $ git log --graph * commit 3c8464613ce94ff78372ce5c0fbf049d2fa5524e | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 22:51:10 2012 -0200 | | Add example file. | * commit e1dbf27ef62cef023437a710f5101dbf762efbef | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add old file. | ~/ancestry [master] $ git rebase –i HEAD~3
  • 29. #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 commits 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
  • 30. #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 #
  • 31. #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.
  • 32. #12 INTERACTIVE REBASE   ~/ancestry [master] $ git log --graph * commit 952118d7fb53a33040f50707053ee1499f0728b9 | Author: Rodolfo Spalenza <rodolfo.spalenza@gmail.com> | 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 <rodolfo.spalenza@gmail.com> | Date: Tue Dec 11 22:16:26 2012 -0200 | | Add new file. |
  • 33. 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