threads / discuss / 16560

Overwrite master

Subject: Overwrite master

## tl;dr

4 messages between Dec 2, 2008 and Dec 2, 2008.

replies: 3people: 2as markdown or json

Nicholas Wieland· Dec 2, 2008, 16:10 UTC · lore

Hi *, I need to overwrite my master branch with another branch. I've already created a backup branch of my master. I tried a merge but it's just too big to handle, and I don't really care about what's in my master now. The reason I want to do something like this is to be able to branch directly from my master in the future and merge back smaller branches (basically what I didn't do this time ...) instead of trying to merge back a huge one. This time I've used git like I've used svn, my bad, very stupid thing ... Hope my question is clear.

TIA,
   ngw
Peter Harris· Dec 2, 2008, 16:32 UTC · re: Nicholas Wieland · lore

Re: Overwrite master

On Tue, Dec 2, 2008 at 11:10 AM, Nicholas Wieland wrote:
> Hi *,
> I need to overwrite my master branch with another branch. I've already
> created a backup branch of my master.

While on master, "git reset --hard <newbranch>"

Or while on a different branch, git branch -D master git branch master <newbranch>

Peter Harris
Nicholas Wieland· Dec 2, 2008, 20:09 UTC · re: Peter Harris · lore

Re: Overwrite master

Il giorno 02/dic/08, alle ore 17:32, Peter Harris ha scritto:
Show 12 quoted lines
> On Tue, Dec 2, 2008 at 11:10 AM, Nicholas Wieland wrote:
>> Hi *,
>> I need to overwrite my master branch with another branch. I've  
>> already
>> created a backup branch of my master.
>
> While on master,
> "git reset --hard <newbranch>"
>
> Or while on a different branch,
> git branch -D master
> git branch master <newbranch>

That's what I tried. Unfortunately I don't know where to go after:

ngw@slicingupeyeballs ~/zooppa$ git commit # On branch master # Your branch and 'origin/master' have diverged, # and have 444 and 25 different commit(s) each, respectively. # nothing to commit (working directory clean)

Do I have to push ? If I pull it tries to merge ...
Thanks a lot for your time,
   ngw
Peter Harris· Dec 2, 2008, 20:28 UTC · re: Nicholas Wieland · lore

Re: Overwrite master

On Tue, Dec 2, 2008 at 3:09 PM, Nicholas Wieland wrote:
Show 20 quoted lines
> Il giorno 02/dic/08, alle ore 17:32, Peter Harris ha scritto:
>
>> On Tue, Dec 2, 2008 at 11:10 AM, Nicholas Wieland wrote:
>>>
>>> Hi *,
>>> I need to overwrite my master branch with another branch. I've already
>>> created a backup branch of my master.
>>
>> While on master,
>> "git reset --hard <newbranch>"
>
> That's what I tried.
> Unfortunately I don't know where to go after:
>
> ngw@slicingupeyeballs ~/zooppa$ git commit
> # On branch master
> # Your branch and 'origin/master' have diverged,
> # and have 444 and 25 different commit(s) each, respectively.
> #
> nothing to commit (working directory clean)
That means your tracking branch is different from your local branch, by a lot.
> Do I have to push ? If I pull it tries to merge ...
If you push, it will be denied (non-fast-forward).

If you force push, your state will be as you expect. Be aware that you're creating trouble for everyone else who uses 'origin' if you force push. Also be aware that you will be undoing any changes that anyone else has pushed to origin in the mean time.

Basically, history is history. If you don't want to cause problems for the other users of 'origin', you may have to live with history as it is. You won't be able to overwrite master, although you will probably try to be more careful in the future.

Peter Harris

← back to recent threads