Moving a repo from github to stash is not working exactly even followed the docs..

Our company decided to move to Stash this week from github. We created all bare repos in stash for the ones in github. 

Everything was pushed fine to stash after following the procedure mentioned in the docs here: https://confluence.atlassian.com/display/STASH/Importing+code+from+an+existing+project#Importingcodefromanexistingproject-ImportanexistingGitprojectintoStash

Except for one repo- the release team accidentally created a 'Readme' file on master branch inside the bare repo in stash.

So we removed that 'Readme' file , made a commit to that master in stash remote.

When we tried `git push --all stash` where stash is the name of the remote of stash repo, added to github repo cloned locally. (just like mentioned in the docs above ), it obviously didnt push to master as expected. 

It says we need to update master with changes in remote. Use git pull.

Doing a git pull from github remote master branch, that has like 700 commits, it applies each patch, so there are conflicts after each patch. 

Solving each conflict and then rebase --continue is really tiresome.  

at this point im not sure what exactly to do now. 

The situation can be summed up : 

  • Github remote master has 700 commits.  
  • Stash remote master 2 commits ( init , and 'remove readme' )
  • when doing `git push --all stash` it fails for master branch saying master needs to be updated with changes from remote.
  • so did `git pull <github-remote-name> master`
  • it applies patch by patch
  • that leads to conflicts after each patch is applied .
  • so solving each patch by hand and doing `git rebase --continue` is going to take a long long time for 700 commits .

Any suggestions /help appreciated. ;((

2 answers

1 accepted

This widget could not be displayed.
Chris Fuller Atlassian Team Apr 04, 2015

I would do the merge manually to "throw away" the content of the README that you don't want.  I believe that would look like this:

 

Option 1: Preserve history
 

git fetch --all                  # Make sure you have up-to-date info 
git reset --hard origin/master   # Start from what was on github
git merge -s ours stash/master   # Create a merge that ignores stash's changes
git push stash master            # Pushes up that merge commit

 

The drawback is that this extra commit will be in your history forever, but the good news is that nobody gets hurt. smile  If you want to live a little bit more dangerously, you can simply overwrite the master using a forced push.  There are some nasty consequences to trying to rewrite history like this, but if nobody else has tried to use the repository from stash yet, then you should be okay:

Option 2: Rewrite history
 

git fetch --all                  # Make sure you have up-to-date info
git reset --hard origin/master   # Start from what was on github
git push -f stash master         # Force push the master branch to stash

 

You should then restrict forced pushes to administrators, if you haven't already done so.

 

 

Thanks it worked :). First solution worked right away, though second would work too but we have read/write restrictions on rewriting history from admins.

This widget could not be displayed.

If the repo on Stash contains nothing but those two commits, which you don't really want, couldn't you just delete the repo and recreate it empty?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,319 views 8 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you