Skip to content

Instantly share code, notes, and snippets.

@joshbrand
Last active December 25, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshbrand/7029313 to your computer and use it in GitHub Desktop.
Save joshbrand/7029313 to your computer and use it in GitHub Desktop.
Git Primer

Setup

  • Fork rackerlabs/salt-queues to your account in github
  • Checkout your fork:
➜  tmp  git clone git@github.com:joshbrand/salt-queues.git
Cloning into 'salt-queues'...
remote: Counting objects: 763, done.
remote: Compressing objects: 100% (450/450), done.
remote: Total 763 (delta 315), reused 698 (delta 262)
Receiving objects: 100% (763/763), 119.82 KiB, done.
Resolving deltas: 100% (315/315), done.
  • Add rackerlabs/salt-queues as an upstream remote:
➜  tmp  cd salt-queues 
➜  salt-queues git:(master) git remote add upstream git@github.com:rackerlabs/salt-queues.git

Updating branches

  • Check out the test branch
➜  salt-queues git:(master) git checkout test             
Branch test set up to track remote branch test from origin.
Switched to a new branch 'test'
➜  salt-queues git:(test) git branch -v
  master 401a76a temporary graylog endpoint
* test   354affb Merge pull request #9 from ozgurakan/test
  • Here's the fun part. Pull upstream changes from test, into your local test branch:
➜  salt-queues git:(test) git fetch upstream
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 8 (delta 4), reused 5 (delta 1)
Unpacking objects: 100% (8/8), done.
From github.com:rackerlabs/salt-queues
 * [new branch]      master     -> upstream/master
 * [new branch]      salt01     -> upstream/salt01
 * [new branch]      test       -> upstream/test
➜  salt-queues git:(test) git merge upstream/test    
Updating 354affb..815ee97
Fast-forward
 base/pillar/top.sls                             | 10 ++++++++++
 marconi/base/graylog2/files/graylog2-conf.jinja |  5 +++++
 2 files changed, 15 insertions(+)
  • Your test branch and upstreams are now in sync.

Doing Stuff

  • Using my local (updated) test branch, create a new branch for the feature/fix/trello card I'm working on:
➜  salt-queues git:(test) git branch -v
  master 401a76a temporary graylog endpoint
* test   815ee97 [ahead 4] Merge pull request #11 from ozgurakan/prev-ord
➜  salt-queues git:(test) git checkout -b new_feature
Switched to a new branch 'new_feature'
  • Do stuff
➜  salt-queues git:(new_feature) touch new_thing
➜  salt-queues git:(new_feature) ✗ touch new_other_thing
  • Commit stuff
➜  salt-queues git:(new_feature) ✗ git add new_thing new_other_thing
➜  salt-queues git:(new_feature) ✗ git commit -m "new cool feature" new_thing new_other_thing 
[new_feature 506407b] new cool feature
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 new_other_thing
 create mode 100644 new_thing
  • You can now locally see what you've changed against upstream:
➜  salt-queues git:(new_feature) git fetch upstream
➜  salt-queues git:(new_feature) git --no-pager diff upstream/test
diff --git a/new_other_thing b/new_other_thing
new file mode 100644
index 0000000..e69de29
diff --git a/new_thing b/new_thing
new file mode 100644
index 0000000..e69de29
  • If there are changes upstream you need to include, repeat the fetch/merge process above.

  • When you're ready, push your branch to origin, so you can submit your pull request.

➜  salt-queues git:(new_feature) git push origin new_feature 
Counting objects: 16, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (11/11), 1.30 KiB, done.
Total 11 (delta 4), reused 0 (delta 0)
To git@github.com:joshbrand/salt-queues.git
 * [new branch]      new_feature -> new_feature
  • Return to github, and submit your pull request, making sure to submit it against the test branch, as opposed to master.

Handy Links/Demos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment