How to change the branching point in Git?

Suppose I have the following structure in my git repo:

          C'---D'---E'---F'    (dev)
A---B---C---D---E---F       (master)

I would like to pull C' into the master branch and change the branching point to C', i.e., I want to turn the above into

              D'---E'---F'     (dev)
A---B---C---C'---D---E---F  (master)

I believe I should use a combination of cherry-picking and rebasing, but I am confused about how to do so exactly. Which sequence of operations should I perform?

Suggestion after comments for a clearer schema (since same-letter commits in the original were in fact unnecessary)

          G---H---I---J   (dev)
A---B---C---D---E---F     (master)

with the associated expected result :

              H---I---J    (dev)
A---B---C---G---D---E---F  (master)

The short answer, for your new diagram, is you rebase off G with:

git checkout master
git rebase <commit_id_G>

The longer answer is that you're having difficulty seeing this because you're thinking of master as the "main" branch, and thinking of dev as the "offshoot". But, of course, these branch names are just labels, and you can consider either of them as the "main" branch.

And, since master is the branch we actually want to change, we can redraw the diagram like this:

          H---I---J        (master)
A---B---C---D---E---F---G  (dev)

with the associated expected result :

              H'--I'--J'    (master)
A---B---C---D---E---F---G   (dev)

Hopefully it's easier to see here, that we simply need to rebase master off this new D instead of C.

Change branching point in git, Since no commits have been added to BranchA yet, you can simply reset it to Branch2 : git checkout BranchA git reset --hard Branch2. Had there been any� You want the branch to point to a different commit. You can do that by running. git branch -f <branch-name> <starting-branch> Note that if branch-name is the current branch, you have to switch to a different branch first, for example with git checkout master.

You just need to rebase master onto G:

git checkout master
git rebase <id-of-G>

That will rewrite all the commits found in master which aren't found in G on top of G. There's no need for cherry-picking. Your dev branch will be unchanged.

Basic Branching and Merging, This is an important point to remember: when you switch branches, Git resets your Your change is now in the snapshot of the commit pointed to by the master� Figure 18. A simple commit history. You’ve decided that you’re going to work on issue #53 in whatever issue-tracking system your company uses. To create a new branch and switch to it at the same time, you can run the git checkout command with the -b switch: $ git checkout -b iss53 Switched to a new branch "iss53".

You would need to do the following:

Take not of the hash-refs of these commits: C, C', D, E, F. Then:

  1. git checkout master
  2. git reset --hard C
  3. git cherry-pick C'
  4. git checkout dev
  5. git rebase -i master (interactive rebase to get rid of C')
  6. git checkout master
  7. git cherry-pick D
  8. git cherry-pick E
  9. git cherry-pick F

Push both branches with --force to finish.

I do not recommend this if you're not comfortable with git but that's how I would go about it if absolutely needed to do it like that.

You can always go this route

                           D'---E'---F'     (dev)
A---B---C---D---E---F---C'  (master)

and just cherry-pick C' then rebase your dev branch against master. That would be the simplest solution.

Branches in a Nutshell, Figure 14. HEAD points to the current branch. What is the significance of that? Well, let's do another commit: $ vim test.rb $ git commit -a -m 'made a change'. Additionally you can checkout a new local branch and reset it to the remote branches last commit. git checkout -b <branchname>git reset --hard origin/<branchname>. Detached HEADS. Now that we’ve seen the three main uses of git checkouton branches, it's important to discuss the “detached HEAD”state.

Git: How to rebase your feature branch from one branch to another , Just doing a simple git rebase production from my-feature-branch will not work, as it will move commits 3 through 6 to production, effectively merging master into � A solution relying on the order of parents of a commit obviously won't work in situations where a branch has been fully integrated at some point in the branch's history. git commit --allow-empty -m root # actual branch commit git checkout -b branch_A git commit --allow-empty -m "branch_A commit" git checkout master git commit --allow-empty -m "More work on master" git merge -m "Merge branch_A into master" branch_A # identified as branch point git checkout branch_A git merge --ff-only master

Move branch pointer to different commit without checkout, In case if you just want to move a branch to another commit: $ git branch -f branch -name new-tip-commit. In order to move a branch pointer:. 1. Pick the branch you need. Use git branch -v. You see a list of existing local branches. Grab the branch name that suits your needs. 2. Move HEAD to it. Use git checkout <branch_name> You will see Switched to branch <branch_name>. Success!

Branching and merging, How to combine the changes of parallel tracks of work? How can I permanently reference a point in history, like a software version? Objectives. Be able to create � A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master. As you start making commits, you’re given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically.