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
- Is it easier to manage code with Git or Bazaar?
- How to skip the commit message step in “git commit --amend”?
- Subversion - dealing with code generation
- Why is Visual Studio constantly crashing?
- How do I create a new git branch with the difference of two branches?
- What is a recommended way to manage git patch queues in unrelated repositories
I regularly work in my
origin repo’s master branch and when ready, I submit the same via pull request to
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).
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 (
Alternate Solution: Create a new branch
new_branch from your current branch then
$ 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