master origin/master :> git clone [email protected]:stevenharman/foo.git :> cd foo :master> start by cloning a copy of that remote repository (conventionally known as “origin”) to our local machine.
master origin/master local Git repository (your clone) master feature origin/master :master> git checkout -b feature :feature> [... hackity-hack-hack ...] :feature> git commit -am ‘did something awesome.’ we need to work a sweet new feature. step 1) create a local branch to work in. step 2) hackity-hack-hack. step 3) commit the changes. [repeat steps 2 & 3 as necessary]
master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master // someone else pushed a change to the remote. a teammate, or maybe even another you, has pushed some new changes.
master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature :feature> git fetch origin get any new changes that are on the remote, but not local.
master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master :feature> git checkout master :master> git merge origin/master merge the changes from the remote “master” branch into our local “master” branch. because there are no divergent changes on our local master, this is a “fast-forward merge” along the master’s graph.
master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master :master> git merge feature now we need to merge our feature into “master” so we can release it. option 1) merge feature in. [keeps all info, but we end up with a noisy history graph that’s hard to follow]
master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master OR [go back to just after we merged in the fetched changes]
master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master :master> git checkout feature :feature> git rebase master option 2) rebase our “feature” branch on top of “master”. this “rewinds” our branch back to where it started, then “fast-forwards” along “master”, and finally re-applies each of our change sets. afterward, our local commits have a new SHA1 hash, meaning they are different objects than before rebase, however, the original committer info & meta-data are preserved.
master origin/master local Git repository (your clone) master feature origin/master remote Git repository (origin) master local Git repository (your clone) master feature origin/master local Git repository (your clone) master origin/master feature local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master local Git repository (your clone) master feature origin/master :feature> git checkout master :master> git merge feature now we can merge our changes into “master.” because we already have all of the changes that exist in “master,” this results in a “fast-forward” merge onto “master”.