Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GIT BASICS
- LEVEL 1SAME OLD STORY
- !
- s
- e
- u
- s
- s
- I
- n
- o
- i
- t
- a
- r
- o
- b
- a
- l
- l
- Co
- LEVEL 1 — GIT BASICSVERSION CONTROL SYSTEMS
- Merging
- Ti
- e
- l
- u
- s
- p
- a
- C
- e
- mREPOSITORY LOCATIONS
- Central Repository
- LEVEL 1 — GIT BASICS
- Distributed RepositoryGit is a
- DISTRIBUTED VERSION CONTROL SYSTEM
- (DVCS)WORKING WITH GIT
- • Command line interface
- • Many GUI tools available
- • Official Git Site —
- http://git-scm.com/
- start here
- LEVEL 1 — GIT BASICSGIT HELP
- $ git help
- usage: git [--version] [--exec-path[=<path>]] [--html-path]
- [-p|--paginate|--no-pager] [--no-replace-objects]
- [--bare] [--git-dir=<path>] [--work-tree=<path>]
- [-c name=value] [--help]
- <command> [<args>]
- The most commonly used git commands are:
- add
- Add file contents to the index
- bisect
- Find by binary search the change that introduced a bug
- ...
- LEVEL 1 — GIT BASICSGIT HELP
- $ git help config
- GIT-CONFIG(1)
- Git Manual
- GIT-CONFIG(1)
- pass in any git command
- NAME
- git-config - Get and set repository or global options
- SYNOPSIS
- git config [<file-option>] [type] [-z|--null] name [value [value_regex]]
- git config [<file-option>] [type] --add name value
- ...
- LEVEL 1 — GIT BASICSSETTING UP GIT
- $ git config --global user.name "Gregg Pollack"
- Who gets credit for changes
- $ git config --global user.email gregg@codeschool.com
- $ git config --global color.ui true
- LEVEL 1 — GIT BASICS
- What email you use
- Pretty command line colorsSTARTING A REPO
- $ mkdir store
- $ cd store
- $ git init
- Initialized empty Git repository in /Users/gregg/store/.git/
- git metadata is stored here
- LEVEL 1 — GIT BASICSGIT WORK FLOW
- Jane creates README.txt file
- Starts as untracked
- Add file to staging area
- Getting ready to take a picture
- Commit changes
- A snapshot of those on the stage
- LEVEL 1 — GIT BASICSGIT WORK FLOW
- Jane creates README.txt file
- Add file to staging area
- Commit changes
- Jane modifies README.txt file & adds LICENSE
- Add both files to staging area
- Commit changes
- LEVEL 1 — GIT BASICSJane creates README.txt file
- $ git status
- To check what’s changed since last commit
- # On branch master
- #
- # Initial commit
- #
- # Untracked files:
- #
- (use "git add <file>..." to include in what will be committed)
- #
- Our newly created file
- #
- README.txt
- nothing added to commit but untracked files present (use "git add" to track)
- LEVEL 1 — GIT BASICSAdd file to staging area
- $ git add README.txt
- $ git status
- # On branch master
- #
- # Initial commit
- #
- # Changes to be committed:
- #
- (use "git rm --cached <file>..." to unstage)
- #
- #
- new file:
- README.txt
- #
- Our staged file
- LEVEL 1 — GIT BASICSCommit changes
- Commit message
- what work was done?
- timeline
- $ git commit -m "Create a README."
- [master abe28da] Create a README.
- 1 files changed, 1 insertions(+), 0 deletions(-)
- create mode 100644 README.txt
- master
- $ git status
- # On branch master
- nothing to commit (working directory clean)
- No new or modified files since last commit
- LEVEL 1 — GIT BASICSJane modifies README.txt file & adds LICENSE
- $ git status
- # On branch master
- # Changed but not updated:
- #
- # modified:
- README.txt
- #
- # Untracked files:
- #
- # LICENSE
- no changes added to commit
- LEVEL 1 — GIT BASICS
- masterAdd both files to staging area
- $ git add README.txt LICENSE
- OR
- $ git add --all
- Adds all new or modified files
- $ git status
- # On branch master
- # Changes to be committed:
- #
- # new file:
- LICENSE
- # modified:
- README.txt
- #
- LEVEL 1 — GIT BASICS
- masterCommit changes
- $ git commit -m "Add LICENSE and finish README."
- [master 1b0019c] Add LICENSE and finish README.
- 2 files changed, 21 insertions(+), 0 deletions(-)
- create mode 100644 LICENSE
- LEVEL 1 — GIT BASICS
- masterGIT TIMELINE HISTORY
- $ git log
- commit 1b0019c37e3f3724fb2e9035e6bab4d7d87bf455
- Author: Gregg Pollack <gregg@codeschool.com>
- Date:
- Thu Jul 5 22:31:27 2012 -0400
- Add LICENSE and finish README.
- commit 5acaf86b04aaf9cbbb8ebb9042a20a46d0b9ce76
- Author: Gregg Pollack <gregg@codeschool.com>
- Date:
- Thu Jul 5 22:00:46 2012 -0400
- Create a README.
- LEVEL 1 — GIT BASICS
- masterDIFFERENT WAYS TO ADD
- $ git add <list of files>
- Add the list of files
- $ git add --all Add all files
- $ git add *.txt Add all txt files in current directory
- $ git add docs/*.txt
- $ git add docs/
- $ git add "*.txt"
- LEVEL 1 — GIT BASICS
- Add all txt files in docs directory
- Add all files in docs directory
- Add all txt files in the whole project
- ___________________________________________________________________________________________________________________________
- STAGING & REMOTES
- LEVEL 2GIT DIFF
- LICENSE
- Copyright (c) 2012 Envy Labs LLC
- ...
- Permission is hereby granted,
- free of charge, to any person
- obtaining a copy
- LICENSE
- edit
- Copyright (c) 2012 Code School LLC
- ...
- Permission is hereby granted, free
- of charge, to any person obtaining
- a copy
- Show unstaged
- $ git diff
- diff --git a/LICENSE b/LICENSE
- index 7e4922d..442669e 100644
- --- a/LICENSE
- +++ b/LICENSE
- @@ -1,4 +1,4 @@
- -Copyright (c) 2012 Envy Labs LLC
- +Copyright (c) 2012 Code School LLC
- differences since last commit
- Line removed
- Line addedVIEWING STAGED DIFFERENCES
- $ git add LICENSE
- $ git diff
- No differences, since all changes are staged
- $ git diff --staged
- View staged differences
- diff --git a/LICENSE b/LICENSE
- index 7e4922d..442669e 100644
- --- a/LICENSE
- +++ b/LICENSE
- @@ -1,4 +1,4 @@
- -Copyright (c) 2012 Envy Labs LLC
- +Copyright (c) 2012 Code School LLC
- LEVEL 2 — STAGING & REMOTESUNSTAGING FILES
- $
- #
- #
- #
- #
- #
- #
- $
- Unstage Tip
- git status
- On branch master
- Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
- modified:
- LICENSE
- Refers to last commit
- git reset HEAD LICENSE
- Unstaged changes after reset:
- M LICENSE
- LEVEL 2 — STAGING & REMOTES
- master
- HEADDISCARD CHANGES
- $ git status
- # On branch master
- # Changed but not updated:
- #
- (use "git add <file>..." to update what will be committed)
- #
- (use "git checkout -- <file>..." to discard changes in working directory)
- #
- # modified:
- LICENSE
- #
- $ git checkout -- LICENSE
- $ git status
- Blow away all changes
- since last commit
- nothing to commit (working directory clean)
- LEVEL 2 — STAGING & REMOTESSKIP STAGING AND COMMIT
- Readme.txt
- here is my readme
- Readme.txt
- edit
- and now I can sleep
- here is my readme
- the cake is a lie
- Add changes from all tracked files
- $ git commit -a -m "Modify readme"
- [master d00fefc] Modify readme
- 1 files changed, 1 insertions(+), 1 deletions(-)
- Doesn’t add new (untracked) files
- LEVEL 2 — STAGING & REMOTES
- master
- HEADUNDOING A COMMIT
- Whoops, we forgot something on that commit.
- Reset into staging
- $ git reset --soft HEAD^
- $
- #
- #
- #
- #
- #
- #
- git status
- On branch master
- Changes to be committed:
- (use "git reset HEAD <file>..." to unstage)
- Move to commit before ‘HEAD’
- modified:
- README.txt
- Now I can make changes, and re-commit
- LEVEL 2 — STAGING & REMOTES
- master
- HEADADDING TO A COMMIT
- Maybe we forgot to add a file
- Add to the last commit
- $ git add todo.txt
- master
- New commit message
- $ git commit --amend -m "Modify readme & add todo.txt."
- [master fe98ef9] Modify readme and add todo.txt.
- 2 files changed, 2 insertions(+), 1 deletions(-)
- create mode 100644 todo.txt
- Whatever has been staged is added to last commit
- LEVEL 2 — STAGING & REMOTES
- HEADUSEFUL COMMANDS
- $ git reset --soft HEAD^
- Undo last commit, put changes into staging
- $ git commit --amend -m "New Message"
- $ git reset --hard HEAD^
- $ git reset --hard HEAD^^
- LEVEL 2 — STAGING & REMOTES
- Change the last commit
- Undo last commit and all changes
- Undo last 2 commits and all changesHOW TO SHARE?
- Remote Repository
- push
- master
- pull
- pull
- “git remote” command
- Git doesn’t take care of access control
- LEVEL 2 — STAGING & REMOTESREMOTE REPOSITORY HOSTING
- Hosted Self Managed
- • GitHub • Gitosis
- • BitBucket • Gitorious
- push
- master
- LEVEL 2 — STAGING & REMOTESLEVEL 2 - STAGING & REMOTESLEVEL 2 - STAGING & REMOTESADDING A REMOTE
- $ git remote add origin https://github.com/Gregg/git-real.git
- New remote
- our name for this remote
- show remote repositories
- $ git remote -v
- origin https://github.com/Gregg/git-real.git (fetch)
- origin https://github.com/Gregg/git-real.git (push)
- LEVEL 2 — STAGING & REMOTES
- address
- originPU SHING TO R EMOTE
- remote repository name
- local branch to push
- $ git push -u origin master
- push
- Username for 'https://github.com': Gregg
- Password for 'https://Gregg@github.com':
- Counting objects: 11, done.
- Delta compression using up to 4 threads.
- Compressing objects: 100% (6/6), done.
- Writing objects: 100% (11/11), 1.50 KiB, done.
- Total 11 (delta 0), reused 0 (delta 0)
- To https://github.com/Gregg/git-real.git
- * [new branch]
- master -> master
- Password caching
- master
- https://help.github.com/articles/set-up-git
- originLEVEL 2 - STAGING & REMOTESSame information from “git log”
- LEVEL 2 - STAGING & REMOTESPU LLING FROM REMOTE
- To pull changes down from the remote
- $ git pull
- remote: Counting objects: 5, done.
- remote: Compressing objects: 100% (1/1), done.
- remote: Total 3 (delta 1), reused 3 (delta 1)
- It’s
- Unpacking objects: 100% (3/3), done.
- From https://github.com/Gregg/git-real
- fe98ef9..4e67ded master
- -> origin/master
- Updating fe98ef9..4e67ded
- Fast-forward
- todo.txt | 1 +
- 1 file changed, 1 insertion(+)
- LEVEL 2 — STAGING & REMOTES
- pull
- origin
- good
- n
- e
- t
- f
- o
- s
- i
- h
- t
- o
- to dHAVING MULTIPLE REMOTES
- production
- origin
- test
- LEVEL 2 — STAGING & REMOTESWORKING WITH REMOTES
- To add new remotes
- $ git remote add <name> <address>
- To remove remotes
- $ git remote rm <name>
- To push to remotes
- $ git push -u <name> <branch>
- usually master
- LEVEL 2 — STAGING & REMOTESUSEFUL COMMANDS
- $ git reset --soft HEAD^
- Don’t do these after
- $ git commit --amend -m "New Message"
- $ git reset --hard HEAD^
- $ git reset --hard HEAD^^
- LEVEL 2 — STAGING & REMOTES
- you push
- ____________________________________________________________________________________________________________________________________________________
- CLONING & BRANCHING
- LEVEL 3COLLABORATING
- “I want a copy”
- “Clone the repo!”
- g
- g
- e
- Gr
- Jane
- push
- local repo
- github
- How do we start collaborating?
- LEVEL 3 — CLONING & BRANCHING
- ?FINDING THE REPO URL
- URL of the remote repository
- LEVEL 3 — CLONING & BRANCHINGFINDING THE REPO URL
- URL of the remote repository
- LEVEL 3 — CLONING & BRANCHINGCLONING A REPOSITORY
- $ git clone https://github.com/codeschool/git-real.git
- Cloning into 'git-real'...
- URL of the remote repository
- $ git clone https://github.com/codeschool/git-real.git git-demo
- Cloning into 'git-demo'...
- local folder name
- LEVEL 3 — CLONING & BRANCHINGGIT CLONE
- 1 - Downloads the entire repository into a new git-real directory.
- 2 - Adds the ‘origin’ remote, pointing it to the clone URL.
- $ git remote -v
- origin
- origin
- https://github.com/codeschool/git-real.git (fetch)
- https://github.com/codeschool/git-real.git (push)
- 3 - Checks out initial branch (likely master).
- sets the head
- LEVEL 3 — CLONING & BRANCHING
- master
- HEADBRANCHING OUT
- Need to work on a feature that will take some time?
- Time to branch out.
- $ git branch cat
- Jane
- cat
- branch created from master
- HEAD
- $ git branch
- cat
- * master
- HEAD still on master
- LEVEL 3 — CLONING & BRANCHING
- masterSWITCHING TO A BRANCH
- Time to jump on that new 'cat' branch.
- Jane
- cat
- $ git checkout cat
- Switched to branch 'cat'
- HEAD
- HEAD is now on ‘cat’
- master
- LEVEL 3 — CLONING & BRANCHINGWORKING ON A BRANCH
- $ echo "Schrödinger" > cat.txt
- $ git add cat.txt
- $ git commit -m "Create quantum cat."
- [cat ab48a3f] Create quantum cat.
- 1 file changed, 1 insertion(+)
- create mode 100644 cat.txt
- cat
- HEAD
- committed to the
- “cat” branch
- master
- LEVEL 3 — CLONING & BRANCHINGWORKING ON A BRANCH
- $ ls
- README.txt cat.txt
- see the cat?
- cat
- HEAD
- master
- LEVEL 3 — CLONING & BRANCHINGBACK TO MASTER
- $ git checkout master
- Switched to branch 'master'
- $ ls
- README.txt
- cat.txt is gone!
- and we’re back on master
- $ git log
- commit 1191ceb7252c9d4b1e05c9969a55766a8adfce3b
- Author: Gregg <gregg@codeschool.com>
- Date:
- Wed Jun 27 23:11:20 2012 -0700
- Add README.
- nothing in the log either
- LEVEL 3 — CLONING & BRANCHING
- cat
- HEAD
- masterBACK TO CAT
- $ git checkout cat
- Switched to branch 'cat'
- $ ls
- README.txt cat.txt
- cat
- phew, still here
- HEAD
- master
- LEVEL 3 — CLONING & BRANCHINGTIME TO MERGE
- Done with that feature branch? Time to merge it into 'master '.
- $ git checkout master
- Switched to branch 'master'
- $ ls
- README.txt
- HEAD
- no cat, as expected
- $ git merge cat
- Updating 1191ceb..ab48a3f
- Fast-forward
- cat.txt |
- 1 +
- 1 file changed, 1 insertion(+)
- create mode 100644 cat.txt
- what’s that?
- merge brings one branch’s changes into another
- master
- catFAST-FORWARD TO THE FUTURE
- Conditions for a fast-forward merge
- master
- HEAD
- cat
- nothing new
- LEVEL 3 — CLONING & BRANCHING
- something newBRANCH CLEAN UP
- When you’re done with a branch, you can safely remove it.
- $ git branch -d cat
- Deleted branch cat (was 957dbff).
- LEVEL 3 — CLONING & BRANCHING
- master
- HEAD
- catNON-FAST-FORWARD
- Let’s work on a new admin feature.
- h
- c
- n
- a
- r
- b
- t
- u
- o
- s
- k
- c
- e
- h
- c
- d
- n
- a
- s
- e
- creat
- $ git checkout -b admin
- Switched to a new branch 'admin'
- ...
- $ git add admin/dashboard.html
- $ git commit -m 'Add dashboard'
- ...
- $ git add admin/users.html
- $ git commit -m 'Add user admin'
- “Please fix the bugs on master.”
- LEVEL 3 — CLONING & BRANCHING
- master
- admin
- HEADBUG FI XING ON MASTER
- Time to put out the fire. We’ll get back to that admin branch later.
- $ git checkout master
- Switched to branch 'master'
- $ git branch
- admin
- * master
- $ git pull
- ...
- $ git add store.rb
- $ git commit -m 'Fix store bug'
- ...
- $ git add product.rb
- $ git commit -m 'Fix product'
- ...
- $ git push
- master
- admin
- HEAD
- HEADBACK TO OUR BRANCH
- $ git checkout admin
- Switched to branch 'admin'
- ...
- master
- admin
- When ready to bring in changes
- $ git checkout master
- Switched to branch 'master'
- $ git merge admin
- LEVEL 3 — CLONING & BRANCHING
- HEAD
- HEADAND SUDDENLY...
- Git uses Vi if no default editor is set to edit commit messages.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- Merge branch 'admin'
- #
- #
- #
- #
- #
- :wq
- DON
- ’T P
- ANI
- Please enter a commit message to explain why this merge is necessary,
- especially if it merges an updated upstream into a topic branch.
- Lines starting with '#' will be ignored, and an empty message aborts
- the commit.
- + hit Enter to write (save) & quit
- Vi commands
- j down k up ESC leave mode :wq save & quit
- h left l right i insert mode :q! cancel & quit
- CRECURSIVE MERGING
- Git can’t fast-forward since changes were made in both branches.
- Merge made by the 'recursive' strategy.
- 0 files changed
- create mode 100644 admin/dashboard.html
- create mode 100644 admin/users.html
- master
- merge commit
- admin
- A commit was created to merge the two branches.
- $ git log
- commit 19f735c3556129279bb10a0d1447dc5aba1e1fa9
- Merge: 5c9ed90 7980856
- Author: Jane <Jane@CodeSchool.com>
- Date:
- Thu Jul 12 17:51:53 2012 -0400
- Merge branch 'admin'
- 2 commits
- 2 commits
- ______________________________________________________________________________________________________________________
- Branching model & Commit
- message formatTask branches
- • Typically, these are called feature branches. We will use a generalized
- variant of the name: task branches.
- • A task branch should almost always be created, at least locally, before
- starting any changes in the code. It should be branched off of the
- develop branch.Before creating a task branch
- • It is a good habit to update your develop branch, prior to creating your task
- branch off of it.
- $ git checkout develop
- # switch to develop
- $ git pull --rebase
- # pull from origin/develop
- • Then proceed to creating and checking out your new task branch
- $ git checkout -b myfe develop
- #Switched to a branch "myfe"Keeping a branch up-to-date
- • Git-flow does not prescribe a way to keep feature branches up-to-
- date. It also assumes they are strictly local, and the original post does
- not discuss remote (shared) feature branches.
- • One could in fact, ignore this topic altogether. Just develop in isolation
- on the dedicated branch, while new code is being pushed to develop.
- And if there is nothing conflicting between develop and the task
- branch, the merge will pass without a hassle.Keeping a branch up-to-date
- • However, if conflicts emerge, they will have to be resolved on develop
- post-merge. Furthermore, if the branch had diverged from develop
- for a long time, and with many commits on both sides, the chances
- for numerous and more complicated conflicts are increasing.
- • Thus, it is advised to periodically update your longer-living task
- branches, to incorporate changes from develop. This should result in
- smaller and more manageable conflicts, which can be resolved on the
- task branch, before merging anything to develop.Updating a local task branch
- • Local longer-living task branches should be updated to include the latest
- content from develop, by doing the following:
- • Update the local develop:
- $ git checkout develop
- # switch to develop
- $ git pull --rebase
- # pull from origin/develop
- $ git checkout task-branch
- # switch to task-branch
- $ git rebase develop
- # rebase task-branch onto develop
- • In case of conflicts reported by the rebase, resolve those on the task
- branch and proceed development on it, or merge it into develop (if
- done).Updating a remote (shared) task branch
- • If a task branch gets pushed to origin (for backup purposes, or for
- collaboration), it should also be kept up-to-date with develop's
- novelties. However, our procedure to update it should be different,
- than the local branch update. Using rebase to update the shared task
- branch, would result in changing the commit history for the other
- users of that branch (after the rebased content is pushed). This can
- cause several undesired complications, so we should do the update
- by merging develop content into our task branch:Updating a remote (shared) task branch
- $ git checkout develop
- $ git pull --rebase
- $ git checkout task-branch
- $ git merge --no-ff develop
- $ git push origin task-branch
- # switch to develop
- # pull from origin/develop
- # switch to task-branch
- # merge develop into task-branch
- # push task-branch to originWhen should we not branch?
- • For trivial tasks, we can avoid the hassle of branching. Consider a
- direct commit & push to develop justified, only for changes that are
- small in size and quick to implement, such as single-commit
- bugfixes/mods that are very very likely to "just work".Commit message format
- 1. Separate subject from body with a blank line
- 2. Limit the subject line to 72 characters
- 3. Capitalize the subject line
- 4. Do not end the subject line with a period
- 5. Use imperative in the subject line
- 6. Wrap the body at 72 characters
- 7. Use the body to explain what and why vs. how
- Read more http://chris.beams.io/posts/git-commit/
- ______________________________________________________________________________________________________________
- COLLABORATION BASICS
- LEVEL 4I want a co
- py
- github
- push
- Gregg
- ?
- Jane
- Clone the repo
- $ git clone https://github.com/codeschool/git-real.git
- Start making changes
- Jane adds two filesTWO NEW FILES
- jane $ git status
- # On branch master
- # Untracked files:
- #
- (use "git add <file>..." to include in what will be committed)
- #
- # product.rb
- # store.rb
- nothing added to commit but untracked files present
- jane $ git add --all
- jane $ git commit -m "Add store and product models."
- [master 30ce481] Add product and store models.
- 2 files changed, 2 insertions(+)
- create mode 100644 product.rb
- create mode 100644 store.rbCOMMIT FLOW
- Sends her new commit
- jane $ git push
- Counting objects: 5, done.
- Compressing objects: 100% (2/2), done.
- Writing objects: 100% (4/4), 441 bytes, done.
- Total 4 (delta 0), reused 0 (delta 0)
- To https://github.com/codeschool/git-real.git
- 4e67ded..30ce481 master -> master
- github
- push new commits
- master
- LEVEL 4 — COLLABORATION BASICSDIFFERENT GIT COMMITS
- gregg $ git commit -am "Update the readme."
- [master c715339] Update the readme.
- 1 file changed, 1 insertion(+), 1 deletion(-)
- gregg
- different
- github
- same
- LEVEL 4 — COLLABORATION BASICS
- ?
- w
- o
- n
- s
- n
- e
- p
- p
- a
- h
- t
- a
- WhGIT PUSH REJECTED
- gregg $ git push
- Cannot write over Jane’s commit
- To https://github.com/codeschool/git-real.git
- ! [rejected]
- master -> master (non-fast-forward)
- error: failed to push some refs to 'https://github.com/codeschool/git-real.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.
- hint: See the 'Note about fast-forwards' in 'git push --help' for details.
- $ git pull
- ...
- $ git push
- ...
- Success!
- LEVEL 4 — COLLABORATION BASICSUNDERSTANDING PULL
- $ git pull
- 1. Fetch (or Sync) our local repository with the remote one
- gregg
- $ git fetch
- github
- origin
- Fetch doesn’t actually update any of our local codeUNDERSTANDING PULL
- $ git pull
- 1. Fetch (or Sync) our local repository with the remote one
- gregg
- master
- origin/master
- $ git fetch
- github
- master
- 2. Merges the origin/master with master $ git merge origin/masterMERGE COMMIT
- $ git pull
- 1. Fetch (or Sync) our local repository with the remote one
- 2. Merges the origin/master with master $ git merge origin/master
- Create a new commit for this merge
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- my editor
- Merge branch 'master' of https://github.com/codeschool/git-real
- #
- #
- #
- #
- #
- Please enter a commit message to explain why this merge is necessary,
- especially if it merges an updated upstream into a topic branch.
- Lines starting with '#' will be ignored, and an empty message aborts
- the commit.GIT PUSH REJECTED
- $ git pull
- remote: Counting objects: 5, done.
- remote: Compressing objects: 100% (2/2), done.
- remote: Total 4 (delta 0), reused 4 (delta 0)
- Unpacking objects: 100% (4/4), done.
- From https://github.com/codeschool/git-real
- 4e67ded..30ce481 master
- -> origin/master
- Merge made by the 'recursive' strategy.
- product.rb | 1 +
- store.rb
- | 1 +
- 2 files changed, 2 insertions(+)
- create mode 100644 product.rb
- create mode 100644 store.rb
- merge commitMERGE COMMIT
- $ git pull
- 1. Fetch (or Sync) our local repository with the remote one
- 2. Merges the origin/master with master
- master
- merge commit
- origin/master
- $ git fetch
- $ git merge origin/masterPU SHING COMMITS
- $ git push
- Update origin/master be at the same state as our local repo
- origin/master
- master
- merge commit
- githubOUR LOG
- gregg $ git log
- commit ee47baaedcd54e1957f86bda1aaa1b8a136185da
- Merge: 87c5243 57501d5
- Author: Gregg Pollack <Gregg@CodeSchool.com>
- The problem with pull
- Merge branch 'master' of https://github.com/Gregg/git-real
- commit 87c5243d2266f05cd9fda8b1c9137f11b3fe6f31
- Author: Gregg Pollack <Gregg@CodeSchool.com>
- Update the readme.
- commit 57501d595b16e2d1198a9c04c547a5b1380a6618
- Author: Gregg Pollack <Gregg@CodeSchool.com>
- Add store and product models.MERGE CONFLICTS
- README
- README
- Gregg
- here is my readme
- committed
- different
- same
- Jane
- the cake is telling the truth!
- the cake is a lie
- gregg
- here is my readme
- github
- committed & pushedMERGE CONFLICT
- gregg $ git pull
- remote: Counting objects: 5, done.
- remote: Compressing objects: 100% (1/1), done.
- remote: Total 3 (delta 1), reused 3 (delta 1)
- Unpacking objects: 100% (3/3), done.
- From https://github.com/Gregg/git-real
- ee47baa..4e76d35 master
- -> origin/master
- Auto-merging README.txt
- CONFLICT (content): Merge conflict in README.txt
- Automatic merge failed; fix conflicts and then commit the result.
- Git modified this file with the diff
- LEVEL 4 — COLLABORATION BASICSMERGE CONFLICT
- gregg $ git status
- # On branch master
- # Your branch and 'origin/master' have diverged,
- # and have 1 and 1 different commit each, respectively.
- #
- # Unmerged paths:
- #
- (use "git add/rm <file>..." as appropriate to mark resolution)
- #
- # both modified:
- README.txt
- #
- no changes added to commit (use "git add" and/or "git commit -a")
- Need to edit these files
- LEVEL 4 — COLLABORATION BASICSMERGE CONFLICT
- README
- Edit file and correct
- here is my readme
- here is my readme
- Our local version
- the
- Jane’s version
- <<<<<<< HEAD
- the cake is a lie.
- =======
- the cake is telling the truth!
- >>>>>>>
- 4e76d3542a7eee02ec516a47600002a90a4e4b48
- gregg $ git commit -a
- Merge commit
- LEVEL 4 — COLLABORATION BASICS
- cake is a lie.COMMIT EDITOR
- gregg $ git commit -a
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- Merge commit
- Editor
- Merge branch 'master' of https://github.com/Gregg/git-real
- Conflicts:
- ▸ README.txt
- #
- # It looks like you may be committing a merge.
- # If this is not correct, please remove the file
- #▸.git/MERGE_HEAD
- # and try again.
- #
- #
- #
- #
- #
- Please enter the commit message for your changes. Lines starting
- with '#' will be ignored, and an empty message aborts the commit.
- On branch master
- Your branch and 'origin/master' have diverged,
- and have 1 and 1 different commit each, respectively.MERGE COMMIT
- origin/master
- master
- master
- Merge commit
- Merge commit
- origin/master
- $ git pushCOLLABORATION BASICS
- LEVEL 4
- ________________________________________________________________________________________________________________
- REMOTE BRANCHES & TAGS
- LEVEL 5WHY CREATE A REMOTE BRANCH?
- • When you need other people to work on your branch.
- • Any branch that will last more than a day.
- Gregg
- LEVEL 5 — REMOTE BRANCHES AND TAGSCREATING A REMOTE BRANCH
- $ git checkout -b shopping_cart
- Switched to a new branch 'shopping_cart'
- $ git push origin shopping_cart
- Counting objects: 10, done.
- Delta compression using up to 4 threads.
- Compressing objects: 100% (6/6), done.
- Writing objects: 100% (6/6), 619 bytes, done.
- Total 6 (delta 2), reused 0 (delta 0)
- To https://github.com/codeschool/git-real.git
- * [new branch]
- shopping_cart -> shopping_cart
- Links local branch to
- the remote branch
- (tracking)
- LEVEL 5 — REMOTE BRANCHES AND TAGSPU SHING TO THE BRANCH
- $ git add cart.rb
- $ git commit -a -m "Add basic cart ability."
- [shopping_cart 2a0dbf9] Add basic cart ability
- 1 file changed, 1 insertion(+)
- create mode 100644 cart.rb
- Pushed changes from branch
- $ git push
- Counting objects: 4, done.
- Delta compression using up to 4 threads.
- Compressing objects: 100% (2/2), done.
- Writing objects: 100% (3/3), 302 bytes, done.
- Total 3 (delta 1), reused 0 (delta 0)
- To https://github.com/codeschool/git-real.git
- 786d7a1..2a0dbf9 shopping_cart -> shopping_cartCREATING A BRANCH
- Hey Jane, I star
- ted a branch
- t
- u
- o
- t
- i
- k
- c
- e
- h
- c
- l
- l
- ’
- I
- ,
- t
- Swee
- LEVEL 5 — REMOTE BRANCHES AND TAGSPU LLING NEW BRANCHES
- $ git pull
- remote: Counting objects: 13, done.
- remote: Compressing objects: 100% (6/6), done.
- remote: Total 9 (delta 3), reused 8 (delta 2)
- Unpacking objects: 100% (9/9), done.
- From https://github.com/Gregg/git-real
- 4e76d35..786d7a1 master
- -> origin/master
- * [new branch]
- shopping_cart -> origin/shopping_cart
- Updating 4e76d35..786d7a1
- Fast-forward
- README.txt | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- LEVEL 5 — REMOTE BRANCHES AND TAGS
- remote branchPU LLING NEW BRANCHES
- $ git branch
- * master
- $ git branch -r
- origin/master
- origin/shopping_cart
- list all remote branches
- $ git checkout shopping_cart
- Branch shopping_cart set up to track remote branch shopping_cart from origin.
- Switched to a new branch 'shopping_cart'
- $ git branch
- master
- * shopping_cart
- !
- h
- s
- u
- p
- d
- n
- a
- e
- t
- u
- b
- i
- r
- t
- n
- o
- c
- n
- a
- c
- e
- w
- Now
- LEVEL 5 — REMOTE BRANCHES AND TAGSREMOTE SHOW
- $ git remote show origin
- * remote origin
- Fetch URL: https://github.com/Gregg/git-real.git
- Push URL: https://github.com/Gregg/git-real.git
- HEAD branch: master
- Remote branches:
- master
- tracked
- shopping_cart tracked
- Local branches configured for 'git pull':
- master
- merges with remote master
- shopping_cart merges with remote shopping_cart
- Local refs configured for 'git push':
- master
- pushes to master
- (up to date)
- shopping_cart pushes to shopping_cart (local out of date)REMOVING A BRANCH
- $ git push origin :shopping_cart
- Deletes remote branch
- To https://github.com/codeschool/git-real.git
- - [deleted]
- shopping_cart
- $ git branch -d shopping_cart
- Must delete local branch manua
- lly
- error: The branch 'shopping_cart' is not fully merged.
- If you are sure you want to delete it, run 'git branch -D shopping_cart'.
- $ git branch -D shopping_cart
- Deleted branch shopping_cart (was ea0a1b9).
- LEVEL 5 — REMOTE BRANCHES AND TAGSWHAT ABOUT GREGG?
- Jane
- Gregg
- LEVEL 5 — REMOTE BRANCHES AND TAGSON DELETED REMOTE BRANCH
- $ git commit -m -a "Add ability to pay."
- [shopping_cart 9851887] Add ability to pay.
- 1 file changed, 1 insertion(+), 1 deletion(-)
- $ git push
- No remote to push to (it’s jus
- Everything up-to-date
- Gregg
- t a local branch now)
- $ git remote show origin
- Remote branches:
- master
- tracked
- refs/remotes/origin/shopping_cart stale (use 'git remote prune' to remove)
- $ git remote prune origin
- To clean up deleted remote br
- anches
- Pruning origin
- URL: https://github.com/codeschool/git-real.git
- * [pruned] origin/shopping_cartREMOTE BRANCH NAMES
- Heroku deploys only master bra
- $ git branch
- * staging
- master
- $ git push heroku-staging staging
- Would not work, would push to staging
- local:remote
- $ git push heroku-staging staging:master
- Will push and deploy staging on heroku
- LEVEL 5 — REMOTE BRANCHES AND TAGS
- nc h
- heroku-stagingTAGGING
- A tag is a reference to a commit (used mostly for release versioning)
- $ git tag
- v0.0.1
- v0.0.2
- list all tags
- $ git checkout v0.0.1
- it
- m
- m
- o
- c
- t
- a
- e
- d
- o
- c
- t
- u
- o
- check
- Text
- To add a new tag
- $ git tag -a v0.0.3 -m "version 0.0.3"
- To push new tags
- $ git push --tags
- LEVEL 5 — REMOTE BRANCHES AND TAGSREMOTE BRANCHES & TAGS
- LEVEL 5
- _________________________________________________________________________________________________________________________
- REBASE BELONG TO US
- LEVEL 6MERGE COMMITS ARE BAD
- Merge branch 'cats'
- origin/master
- master
- Add Cats.
- merge commit
- Merge branch 'master' of http...
- Update the Readme.
- Add product and store models.
- M
- s
- s
- e
- l
- e
- s
- u
- l
- e
- e
- f
- s
- t
- i
- m
- m
- o
- c
- e
- g
- r
- e
- LEVEL 6 — REBASE BELONG TO USDIFFERENT GIT COMMITS
- gregg $ git commit -am "Update the readme."
- [master c715339] Update the readme.
- 1 file changed, 1 insertion(+), 1 deletion(-)
- gregg
- different
- github
- same
- LEVEL 6 — REBASE BELONG TO US
- t
- i
- m
- m
- o
- c
- s
- Jane’GIT PUSH REJECTED
- gregg $ git push
- Cannot write over Jane’s commit
- To https://github.com/codeschool/git-real.git
- ! [rejected]
- master -> master (non-fast-forward)
- error: failed to push some refs to 'https://github.com/codeschool/git-real.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.
- hint: See the 'Note about fast-forwards' in 'git push --help' for details.
- $ git pull
- ...
- $ git push
- !
- e
- p
- o
- N
- ...
- LEVEL 6 — REBASE BELONG TO USFETCH
- gregg $ git fetch
- remote: Counting objects: 5, done.
- remote: Compressing objects: 100% (2/2), done.
- remote: Total 4 (delta 0), reused 4 (delta 0)
- Unpacking objects: 100% (4/4), done.
- From https://github.com/codeschool/git-real
- f35f2f1..71a4650 master
- -> origin/master
- gregg
- github
- Syncs
- but doesn’t merge
- LEVEL 6 — REBASE BELONG TO US
- master
- origin/masterREBASE
- gregg $ git rebase
- 1. Move all changes to master which are not in origin/master to a temporary area.
- temp
- master
- origin/master
- LEVEL 6 — REBASE BELONG TO USREBASE
- gregg $ git rebase
- 1. Move all changes to master which are not in origin/master to a temporary area.
- 2. Run all origin/master commits.
- temp
- master
- origin/master
- 3. Run all commits in the temporary area, one at a time.
- LEVEL 6 — REBASE BELONG TO USREBASE
- gregg $ git rebase
- 1. Move all changes to master which are not in origin/master to a temporary area.
- 2. Run all origin/master commits.
- 3. Run all commits in the temporary area, one at a time.
- master
- Update the Readme.
- No M
- erge
- Add product and store models.
- Comm
- it!LOCAL BRANCH REBASE
- $ git checkout admin
- Switched to branch 'admin'
- $ git rebase master
- ...
- master
- admin
- Rebase
- master
- adminI F AL L GOES WELL, MERGE MAS TER
- $ git checkout master
- Switched to branch 'master'
- $ git merge admin
- ...
- master
- adminWHAT ABOUT CONFLICTS
- gregg
- github
- !
- e
- l
- i
- f
- e
- m
- sa
- Add shopping cart.
- d
- e
- t
- i
- d
- E
- Add lie to readme.
- same
- LEVEL 6 — REBASE BELONG TO US
- Add truth to readme.
- Add product and store models.FETCH
- gregg $ git fetch
- master
- origin/master
- Add shopping cart. Add truth to readme.
- Add lie to readme. Add product and store models.
- LEVEL 6 — REBASE BELONG TO USREBASE
- gregg $ git rebase
- 1. Move all changes to master which are not in origin/master to a temporary area
- origin/master
- temp
- Add truth to readme.
- Add product and store models.
- masterREBASE
- gregg $ git rebase
- 2. Run all origin/master commits.
- temp
- master
- Add shopping cart.
- Add truth to readme.
- Add product and store models.
- Add lie to readme.
- 3. Run all commits in the temporary area, one at a time.REBASE CONFLICT
- gregg $ git rebase
- First, rewinding head to replay your work on top of it...
- Applying: Add lie to readme.
- Using index info to reconstruct a base tree...
- M README.txt
- <stdin>:13: trailing whitespace.
- the cake is a lie, and I am your father!
- warning: 1 line adds whitespace errors.
- Falling back to patching base and 3-way merge...
- Auto-merging README.txt
- CONFLICT (content): Merge conflict in README.txt
- Failed to merge in the changes.
- Patch failed at 0001 Add lie to readme.
- master
- CONFLICT
- When you have resolved this problem run "git rebase --continue".
- If you would prefer to skip this patch, instead run "git rebase --skip".
- To check out the original branch and stop rebasing run "git rebase --abort".REBASE CONFLICT
- gregg $ git status
- # Not currently on any branch.
- # Unmerged paths:
- #
- (use "git reset HEAD <file>..." to unstage)
- #
- (use "git add/rm <file>..." as appropriate to mark resolution)
- #
- # both modified:
- README.txt
- #
- no changes added to commit (use "git add" and/or "git commit -a")
- Edit the README.txt
- gregg $ git add README.txt
- gregg $ git rebase --continue
- Applying: Add lie to readme.
- Applying: Add shopping cart
- gregg $
- masterREBASED LOG
- master
- Add shopping cart.
- Add lie to readme.
- Add truth to readme.
- Add product and store models.REBASE BELONG TO US
- LEVEL 6
- _______________________________________________________________________________________________________________________
- git workflows
- Tomche Delev M.Sc.Workflow
- Guidelines rather than concrete rules
- The way you use and incorporate
- some technology in the daily work
- process.Centralized
- workflowHow it works?
- ● Central repository to serve as the single point-of-entry for
- all changes to the project (master <-> trunk)
- ● Developers clone the central repository
- ● Everything is stored locally isolated from the central
- repositoryPush changesManaging conflictsExamplessh user@host git init --bare /path/to/repo.git
- Someone initializes empty repositorygit clone ssh://user@host/path/to/repo.git
- Everybody clones the central repositorygit status # View the state of the repo
- git add <some-file> # Stage a file
- git commit # Commit a file</some-file>
- John works on his featuregit status # View the state of the repo
- git add <some-file> # Stage a file
- git commit # Commit a file</some-file>
- Mary works on her featuregit push origin master
- John publishes his featureerror: failed to push some refs to '/path/to/repo.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.
- hint: See the 'Note about fast-forwards' in 'git push --
- help' for details.
- git push origin master
- Mary tries to publish her featuregit pull --rebase origin master
- Mary rebases on top of John’s commit(s)Mary rebases on top of John’s commit(s)CONFLICT (content): Merge conflict in <some-file>
- Mary resolves a merge conflictMary resolves a merge conflict#
- #
- #
- #
- #
- Unmerged paths:
- (use "git reset HEAD <some-file>..." to unstage)
- (use "git add/rm <some-file>..." as appropriate to mark resolution)
- both modified: <some-file>
- git add <some-file>
- git rebase --continue
- git rebase --abort
- Mary resolves a merge conflictgit push origin master
- Mary successfully publishes her featureFeature Branch
- WorkflowBasic ideas
- ● The core idea behind the Feature Branch Workflow is that
- all feature development should take place in a dedicated
- branch instead of the master branch.
- ● Pull requests (easy way for your team to comment on each
- other’s work)How it works?
- ● Still uses a central repository, and master still represents
- the official project history
- ● Developers create a new branch every time they start work
- on a new feature (feature branch)
- ○
- ●
- animated-menu-items, issue-#1662
- Feature branches can (and should) be pushed to the
- central repositoryPull Requests
- ● Discuss changes before merge or ask for help
- ●
- Once a pull request is accepted, the actual act of
- publishing a feature is much the same as in the Centralized
- WorkflowExamplegit checkout -b marys-feature master
- git status
- git add <some-file>
- git commit
- Mary begins a new featuregit push -u origin marys-feature
- Mary goes to lunchgit push
- Mary finishes her featureBill receives the pull requestMary makes the changesgit
- git
- git
- git
- checkout master
- pull
- pull origin marys-feature
- push
- Mary publishes her featureMeanwhile, John is doing the exact same thingGitflow
- Workflowhttp://nvie.com/posts/a-successful-git-branching-model/How it works?
- ● The only difference...
- ● It assigns very specific roles to different branches and
- defines how and when they should interact.
- ● In addition to feature branches, it uses individual branches
- for preparing, maintaining, and recording releasesHistorical BranchesFeature BranchesRelease BranchesMaintenance BranchesExamplegit branch develop
- git push -u origin develop
- git clone ssh://user@host/path/to/repo.git
- git checkout -b develop origin/develop
- Create a develop branchgit checkout -b some-feature develop
- git status
- git add <some-file>
- git commit
- Mary and John begin new featuresgit
- git
- git
- git
- git
- pull origin develop
- checkout develop
- merge some-feature
- push
- branch -d some-feature
- Mary finishes her featuregit checkout -b release-0.1 develop
- Mary begins to prepare a releasegit
- git
- git
- git
- git
- git
- git
- checkout master
- merge release-0.1
- push
- checkout develop
- merge release-0.1
- push
- branch -d release-0.1
- git tag -a 0.1 -m "Initial public release" master
- git push --tags
- Mary finishes the releasegit checkout -b issue-#001 master
- # Fix the bug
- git checkout master
- git merge issue-#001
- git push
- git
- git
- git
- git
- checkout develop
- merge issue-#001
- push
- branch -d issue-#001
- End-user discovers a bugForking
- workflowHow it works?
- ● fork the official repository to create a copy of it on the server
- ● git clone to get a copy of it onto local machine
- ● When ready to publish a local commit, push the commit to own public
- repository - not the official one
- ● File a pull request with the main repository, which lets the project
- maintainer know that an update is ready to be integratedHow it works?
- ● The maintainer pulls the contributor’s changes into their local
- repository, checks to make sure it doesn’t break the project, merges it
- into his local master branch
- ● Then pushes the master branch to the official repository on the
- server.
- ● The contribution is now part of the project, and other developers
- should pull from the official repository to synchronize their local
- repositoriesThe Official Repository?
- Branching in the Forking WorkflowExamplessh user@host
- git init --bare /path/to/repo.git
- The project maintainer initializes the official repositoryDevelopers fork the official repositorygit clone https://user@bitbucket.org/user/repo.git
- git remote add upstream https://bitbucket.org/maintainer/repo
- git remote add upstream https://user@bitbucket.org/maintainer/repo.git
- Developers clone their forked repositoriesgit checkout -b some-feature
- # Edit some code
- git commit -a -m "Add first draft of some feature"
- git pull upstream master
- Developers work on their featuresgit push origin feature-branch
- Developers publish their featuresgit fetch https://bitbucket.org/user/repo feature-branch
- # Inspect the changes
- git checkout master
- git merge FETCH_HEAD
- git push origin master
- The project maintainer integrates their featuresgit pull upstream master
- Developers synchronize with the official repositoryThe End
- https://twitter.com/joserobleda/status/707846636345683968References:
- Questions?
- Thank you for your attention!
- https://www.atlassian.com/git/tutorials/comparing-workflows
- http://nvie.com/posts/a-successful-git-branching-model/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement