Forum General

Git "Rebase current branch onto" to create new Branch for test code?

JKnottJKnott Member ✭✭✭

Hello, I have been working on a new function to my code.
I have created a tag on my current Master to be able to be able to pull the last stable build from, but I would like to create a working branch that I can work on without worrying about damaging my stable code base.

I've created a Branch called NeedsWork, and I am trying to commit my current, modified code to it in VisualStudio. When I try to select the new branch it is asking me if I want to "Merge into Current" or "Rebase Current branch onto".

I am assuming "Merge into Current" would be to merge my NeedsWork branch OVER the Master, and that "Rebase Current branch onto" would copy Master to NeedsWork then let me check in my code over that on the NeedsWork branch.

From what I was reading, it said something about Rebasing wiping tags and merge histories, So I wanted to make sure I was understanding this properly.

Thanks for the help! I'm exceptionally new to Git (To give away my age, the last Versioning software I worked with was "Visual Source Safe")

Cheers!

Best Answer

  • JoeMankeJoeManke USMember ✭✭✭✭✭
    Accepted Answer

    Either way, your Master branch should be safe. Merging will create a new commit on the NeedsWork branch, which has two parent commits - the current tips of the Master and NeedsWork branches. Rebasing will mess with the history of NeedsWork, by inserting the commits made to Master between when the two branches last diverged, before the commits made on NeedsWork. If this is a one-man project or you haven't pushed NeedsWork this should be fine, but if anyone else has pulled down the NeedsWork branch, you rebasing will create a headache for them.

    Here's a link with more explanation and some pretty graphs: https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Answers

  • JoeMankeJoeManke USMember ✭✭✭✭✭
    Accepted Answer

    Either way, your Master branch should be safe. Merging will create a new commit on the NeedsWork branch, which has two parent commits - the current tips of the Master and NeedsWork branches. Rebasing will mess with the history of NeedsWork, by inserting the commits made to Master between when the two branches last diverged, before the commits made on NeedsWork. If this is a one-man project or you haven't pushed NeedsWork this should be fine, but if anyone else has pulled down the NeedsWork branch, you rebasing will create a headache for them.

    Here's a link with more explanation and some pretty graphs: https://www.atlassian.com/git/tutorials/merging-vs-rebasing

  • JKnottJKnott Member ✭✭✭

    @JoeManke Excellent, Thanks!
    I figured it was more or less what I was assuming and I see where I got confused about the resetting the history, it's on the NeedsWork branch that it would occur. I just wanted to make sure Master would remain intact. I use GitLab, and I can't find any way to make a backup of the entire repository other than to just download it (Perhaps that copies the entire history too?)
    Sorry I'm such a newbie to Git, The site you sent is perfect! (Explains it all in simple terms with pictures LOL!)

    Cheers!

  • JKnottJKnott Member ✭✭✭

    I think in the end, Since I am working alone, and my code is all related to a common build. I am going to just create tags at the stable checkins and when I start working on an experimental portion of the code.
    I am working on making a free version that uses Admob and just checks the purchase history for the user to see if it should show the free or the paid version of the app (perhaps not the most secure, but in the end it's not government secrets here).
    This way I can just check the tags to see where the last stable code was if I break anything, recheck out that tag, and recheck it in after I have done any bugfixes.

    I know this is less than ideal, but in my one man environment, I think it will be the easier process.

    Thanks again for the info, and the site is going to be great for answering questions down the road. I know Git is far more powerful than VSS and I have heard it's better/easier that Subversion.

    Cheers!

Sign In or Register to comment.