title: working on git branch
body: <p>I've been doing a lot of reading, but am still not too clear on how to work on a git branch in different places. How to do that? </p>
  
  <p>First of all, the reason that I have to work in a branch is that I do have an "upstream" repo, which I need to rebase into my <code>master</code> from time to time. So to keep my addons clean from upstream, I need to work on a git branch. </p>
  
  <p><strong>UPDATE2:</strong></p>
  
  <p>Ok. It's far more complicated than I thought now. The way I did from the source location was, <code>git checkout -b newfeature</code> then pushed wth <code>git push -u origin newfeature</code>, which was done on top of a "upstream" repo, plus my own <code>master</code> repo, setup following the direction of</p>
  
  <ul>
  <li><a href="https://robots.thoughtbot.com/keeping-a-github-fork-updated" rel="nofollow noreferrer">Keeping A GitHub Fork Updated</a> and </li>
  <li><a href="https://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository">How do I update a GitHub forked repository?</a></li>
  </ul>
  
  <p>The problem is that I want to work on such git branch just as working in a normal git -- i.e., when I do some kind of <code>git push</code>, I'm expecting to do some kind of <code>git pull</code> from another location to get the latest updates. </p>
  
  <p>When I'm doing <code>git pull</code> from my second place, I got <code>Already up-to-date</code>. I.e., the remote branch that I want to work on is not available for me. </p>
  
  <p>PS. Info I've found, from
  <a href="http://longair.net/blog/2009/04/16/git-fetch-and-merge/" rel="nofollow noreferrer">http://longair.net/blog/2009/04/16/git-fetch-and-merge/</a></p>
  
  <blockquote>
    <p>If you want to create a local branch based on a remote-tracking branch (i.e. in order to actually work on it) you can do that with git branch –track or git checkout –track -b, which is similar but it also switches your working tree to the newly created local branch. For example, if you see in git branch -r that there’s a remote-tracking branch called origin/refactored that you want, you would use the command:</p>
  </blockquote>
  
  <pre><code>git checkout --track -b refactored origin/refactored
  </code></pre>
  
  <p>However, this is what I got from <code>git branch -r</code> on the source location. </p>
  
  <pre><code>$ git branch -r
    origin/HEAD -&gt; origin/master
    origin/master
  </code></pre>
  
  <p>I.e., there is no remote-tracking branch called origin/something, but I'm clearly working in a branch:</p>
  
  <pre><code>$ git status . 
  On branch newfeature
  nothing to commit, working directory clean
  
  $ git branch -vv
    master     55e1d6f [origin/master] Remove ...
  * newfeature 8c4266a - [+] add ...
  </code></pre>
  
  <p>Since that <code>-r</code> means for remote-tracking branches, I got same result for <code>git branch -r</code> from my second place as well. </p>
  
  <p><strong>UPDATE 3</strong>: </p>
  
  <p>Finally, I can confirm that the problem is at my source end, I.e., the remote tracking branch is not listed. Once again, listing them side-by-side.</p>
  
  <p>First, my current bad source:</p>
  
  <pre><code>$ git branch -r
    origin/HEAD -&gt; origin/master
    origin/master
  
  $ git branch -vv
    master     55e1d6f [origin/master] Remove ...
  * newfeature 8c4266a - [+] add ...
  </code></pre>
  
  <p>Second, what it should be:</p>
  
  <pre><code>$ git branch -r
    origin/HEAD -&gt; origin/master
    origin/master
    origin/newfeature
  
  $ git branch -vv
    master     7b1fc0f [origin/master] Add readme
  * newfeature 7b1fc0f [origin/newfeature] Add readme
                       ^^^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>the output of <code>git config --get-all remote.origin.fetch</code> is the same,  <code>+refs/heads/master:refs/remotes/origin/master</code>, on both sites:</p>
  
  <pre><code>$ git config --get-all remote.origin.fetch
  +refs/heads/master:refs/remotes/origin/master
  </code></pre>
  
  <p><strong>Final UPDATE</strong>: </p>
  
  <p>Thanks to @torek's tireless help, I finally get things straight. Here are the last steps <em>after</em> fixing the <code>.git/config</code> file as directed by @torek:</p>
  
  <pre><code>git checkout master
  # then fix the `.git/config` file
  git config --edit
  
  $ git branch -vv
  * master     55e1d6f [origin/master] Remove ...
    newfeature 8c4266a [origin/newfeature: gone] - [+] add ...
                                           ^^^^
  
  $ git branch -r
    origin/HEAD -&gt; origin/master
    origin/master
    upstream/master
  # The "origin/newfeature" is missing
  
  $ git checkout newfeature
  Switched to branch 'newfeature'
  Your branch is based on 'origin/newfeature', but the upstream is gone.
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    (use "git branch --unset-upstream" to fixup)
  
  $ git branch --set-upstream-to origin/newfeature
  error: the requested upstream branch 'origin/newfeature' does not exist
  hint: 
  hint: If you are planning on basing your work on an upstream
  hint: branch that already exists at the remote, you may need to
  hint: run "git fetch" to retrieve it.
  hint: 
  hint: If you are planning to push out a new local branch that
  hint: will track its remote counterpart, you may want to use
  hint: "git push -u" to set the upstream config as you push.
  
  $ git push -u origin newfeature
  Branch newfeature set up to track remote branch newfeature from origin.
  Everything up-to-date
  
  $ git branch -r
    origin/HEAD -&gt; origin/master
    origin/master
    origin/newfeature
    upstream/master
  # The "origin/newfeature" is now listed
  
  $ git branch -vv
    master     55e1d6f [origin/master] Remove ...
  * newfeature 8c4266a [origin/newfeature] - [+] add ...
  
  # Horay!!!
  </code></pre>
  
  <p>So to recap, to get things correct in the first place, follow the instructions in <a href="http://www.gitguys.com/topics/adding-and-removing-remote-branches" rel="nofollow noreferrer">http://www.gitguys.com/topics/adding-and-removing-remote-branches</a>. I was able to get above correct result with that small demo. I.e., the direction I've been following</p>
  
  <ul>
  <li><a href="https://robots.thoughtbot.com/keeping-a-github-fork-updated" rel="nofollow noreferrer">Keeping A GitHub Fork Updated</a> and </li>
  <li><a href="https://stackoverflow.com/questions/7244321/how-do-i-update-a-github-forked-repository">How do I update a GitHub forked repository?</a></li>
  </ul>
  
  <p>Might or might not be the cause. However, now we have a way to fix it, if you get into the similar situation. </p>
  
  <p><em>Final UPDATE End</em></p>
  
  <p>So, let me ask the final question -- is it possible to correct my bad source? </p>
  
  <p>According to<br>
  <a href="http://gitready.com/intermediate/2009/01/09/checkout-remote-tracked-branch.html" rel="nofollow noreferrer">checkout tracked remote branch</a>, I think the problem is at my source end, I.e., I don't see my branch listed in the tracked remote branch section. Here is mine:</p>
  
  <pre><code>$ git remote show origin
  * remote origin
    Fetch URL: git@github.com:me/myproj.git
    Push  URL: git@github.com:me/myproj.git
    HEAD branch: master
    Remote branch:
      master tracked
    Local branches configured for 'git pull':
      master     merges with remote master
      newfeature merges with remote newfeature
    Local refs configured for 'git push':
      master     pushes to master     (up to date)
      newfeature pushes to newfeature (up to date)
  </code></pre>
  
  <p>When I do <code>git remote show origin</code> from my second place, I don't see the newfeature listed there. </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I see the <code>newfeature</code> in the <code>git ls-remote</code> from my second place:</p>
  
  <pre><code>$ git ls-remote
  From git@github.com:me/myproj.git
  55e1d6fd9048336c7f0b178fbbf78231ca28ff06        HEAD
  55e1d6fd9048336c7f0b178fbbf78231ca28ff06        refs/heads/master
  8c4266a6a98f498c129a2a9e806e00e6c6d196b1        refs/heads/newfeature
  8c4266a6a98f498c129a2a9e806e00e6c6d196b1        refs/tags/v1
  </code></pre>
  
  <p>However, I don't know how to use it from my second place:</p>
  
  <pre><code>$ git checkout --track -b newfeature
  Branch newfeature set up to track local branch master.
  Switched to a new branch 'newfeature'
  </code></pre>
  
  <p>and <code>git log</code> is not showing the commits I've published to github.</p>
  
  <p>Maybe I shouldn't have used the <code>-b</code>? Well, I must:</p>
  
  <pre><code>$ git checkout --track newfeature
  fatal: Missing branch name; try -b
  
  $ git checkout newfeature
  error: pathspec 'newfeature' did not match any file(s) known to git.
  </code></pre>