41236

Git workflow: Merge existing branch to new branch and delete old one

Question:

Scenario: being on master branch

<ol><li>

git checkout <strong><em>target_branch</em></strong>

</li> <li>

git checkout <strong><em>new_branch</em></strong>

</li> <li>

git commit -m: "TARGET BRANCH TASK NUMBER,NEW BRANCH TASK NUMBER: Message"

</li> <li>

git push origin <strong><em>new_branch</em></strong>

</li> <li>

git checkout <strong><em>target_branch</em></strong>

</li> <li>

git push origin <strong><em>target_branch</em></strong>

</li> </ol><blockquote>

merge request (target - <strong><em>target_branch</em></strong>)

</blockquote>

As I understand my <strong><em>new_branch</em></strong> isn't created from <strong><em>target_branch</em></strong> because firstly I made push from <strong><em>new_branch</em></strong> and only then I pushed <strong><em>target_branch</em></strong> (just forgot it).

So help me please do properly the next:

I'm going to work in <strong><em>target_branch</em></strong> with my friend, and we will create our branches from it.

I need now make my <strong><em>new_branch</em></strong> to be created from <strong><em>target_branch</em></strong> and delete old <strong><em>new_branch</em></strong> (that, I suppose, now seems to be created from master not from target_branch).

How can I do this properly (for Git history)?

Answer1:

To change new_branch checked out from target_branch (or master you can use same method):

git checkout target_branch git cherry-pick target_branch..new_branch git branch -f new_branch git checkout new_branch

<strong>Note:</strong>

-If there has cherry-pick conflicts, you can modify and save the conflict files, then use git add . and git cherry-pick --continue. -If you don’t want to rebase new_branch on the top of target_branch, you can use git checkout <an history commit of target_branch>, and then use above commands to rebase new_branch. As below graphs, if you use git checkout B, and after above commands, the branches will look like:

# Original branch structure A---B---C target_branch D---E---F new_branch # After rebase new_branch from commit B A---B---C target_branch \ D'---E'---F' new_branch

Answer2:

To Resolve your issue, Go through below steps :

<ol><li>git checkout <strong><em>target_branch</em></strong></li> <li>git merge <strong><em>new_branch</em></strong></li> <li>git push origin <strong><em>target_branch</em></strong></li> </ol>

You are now at <strong><em>target_branch</em></strong>, Let's Delete Old Branch : <strong><em>new_branch</em></strong>

<ol start="4"><li>git branch -D <strong><em>new_branch</em></strong></li> <li>git branch <strong><em>new_branch</em></strong></li> </ol>

Now you & your friend can make new branches from <strong><em>target_branch</em></strong> & work on <strong><em>new_branch</em></strong>

Recommend

  • Trying to use fabric to check out a git repository to a subdirectory
  • What are the behavioral differences between a daemon and a normal process?
  • Cannot implicitly convert type 'System.Web.Mvc.SelectList' to 'System.Collections.Gen
  • Directory not found while unit testing
  • Can not Resolved FirebaseOptions.Builder().setCredentials()
  • Is changing parent process necessary when daemonize a process?
  • how to perform a modal segue for long press
  • A floating button fixed at the bottom of UITableview with scrollViewDidScroll not working properly
  • float:left paragraph followed by float:none paragraph
  • Accessing Light userdata in Lua
  • how to git push with maven
  • MATLAB Combine matrices of different dimensions, filling values of corresponding indices
  • jQuery ajax security
  • SQL Server Integrated Security from an Azure Web Site
  • How to override List.Add method?
  • Git cleanup/garbage collection on remote VSO git repository
  • How to merge keras sequential models with same input?
  • hibernate sets dirty flag (and issues update) even though client did not change value
  • How can Delete be both a DDL and a DML statement
  • CERN ROOT exporting data to plain text
  • JqueryMobile Popup menu is not working
  • Not able to aggregate on nested fields in elasticsearch
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Using jQuery closest() method with class selector
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • Array.prototype.includes - not transformed with babel
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Incrementing object id automatically JS constructor (static method and variable)
  • Shallow update not allowed (git > 1.9)
  • Symfony2: How to get request parameter
  • jquery mobile loadPage not working
  • SVN: Merging two branches together
  • How to include full .NET prerequisite for Wix Burn installer
  • log4net write single file for each call to log.info
  • Free memory of cv::Mat loaded using FileStorage API
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Getting error when using KSoap library to consume .NET web services
  • Qt: Run a script BEFORE make
  • unknown Exception android
  • Is there any way to bind data to data.frame by some index?