Git: How to ensure new branch is based on upstream master
<p>I've been making a lot of rookie mistakes with github and as a result I'm seeking a foolproof (me-proof!) method for ensuring that:</p>

<p>a) All new branches I create on a fork are based on origin master, not some other branch, and...</p>

<p>b) That my origin master is always up-to-date with upstream master, and...</p>

<p>c) That when/before I commit (push?), my changes are rebased to upstream master.</p>

<p>Here's what I have so far...</p>

<p>To create new branch:</p>

<pre><code>git fetch --all --tag
git pull upstream master
git push origin master
git checkout -b my_branch_name -t origin/master
</code></pre>

<p>To store my changes to that branch:</p>

<pre><code>git add -A
git commit -m "Summary of what changed"
git fetch --all --tag
git pull --rebase upstream master
git push origin my_branch_name
</code></pre>

<p>To load an existing branch at a later date (eg. to do some additional changes resulting from PR feedback):</p>

<pre><code>git fetch --all --tag
git pull upstream master
git push origin master
git checkout my_branch_name -t origin/master
</code></pre>

<p>And then to save my updates to that branch:</p>

<pre><code>git add -A
git commit --amend --no-edit
git fetch --all --tag
git pull --rebase upstream master
git push origin my_branch_name -f
</code></pre>

<p>I must confess I don't fully comprehend what some of these commands do - there seems to be lots of ways to do lots of similar sounding things and despite lots of googling/reading I'm still a rookie.</p>

<p>Any guidance very much appreciated!</p>