git create branch in my repo that is not spun off from existing branches

I have a repo that I forked from another repo.

Let us call my repo as origin and the parent repo as upstream

I regularly work in my origin repo’s master branch and when ready, I submit the same via pull request to upstream.

Recently, I did a lot of work in my origin repo’s master branch and created a PR to upstream but since the work was quite a bit, it ran into several issues related to conflicts, tests etc etc.

Now another important task came up that I need to work upon.

But when I try to create git checkout -b branch_for_new_work, it takes all the changes from the master branch of origin repo. How do I create a branch whose code-base aligns with the remote repo’s master branch and not my origin repo’s master branch? (I now know that its a good practice to create branches for such work and not pollute the master).

  • If git only records a “snapshot” of your files, then how does it undo a change?
  • How to setup VisualSVN Setup on Windows Azure Instance
  • Can GitHub show the history of changes made to one file in patch form?
  • git branch -r not showing all remote branches
  • Why people name a directory “vendor” which contains all programs that are made by others?
  • How does git track source code moved between files?
  • git procedure to merge branches from origin
  • Is there a way to prevent code comments to be marked as changes in the diffs obtained from version control? (CVS/SVN)
  • One Solution collect form web for “git create branch in my repo that is not spun off from existing branches”

    How do I create a branch whose code-base aligns with the remote repo’s master branch and not my origin repo’s master branch?

    $ git fetch upstream
    $ git checkout -b <new-branch> upstream/master     # create a new branch with upstream/master history
    

    If you want to create a Pull request where base: upstream/master and compare: origin/master then, always pull upstream/master into your origin/master to avoid Conflicts.


    fatal: Cannot update paths and switch to branch ‘new_branch’ at the same time

    Make sure you have fetched your remote (upstream here).


    Alternate Solution: Create a new branch new_branch from your current branch then reset local new_branch with upstream/master

    $ git remote -v              # make sure your remote name is 'upstream' or else
    
    $ git fetch upstream
    $ git checkout -b new_branch
    
    $ git reset --hard upstream/master    
    
    Git Baby is a git and github fan, let's start git clone.