Table of Contents
A colleague of mine forked a repo on Stash, just to re-use configuration. A better way of doing things would be to clone the original repo, keep the necessary config/setup files, delete .git folder, and re-initialize the new repo from scratch.
In our case, we only noticed the fork about a week into the project, so we didn’t want to lose the history for a week’s worth of changes. I tried finding an easy solution for getting rid of the fork reference, but couldn’t find any advice for Atlassian Stash.
As it turns out the problem had a really easy fix, following the steps bellow. Note that I took a more careful approach, to test things out.
Solution for Atlassian Stash
Careful Approach
- Created new repo named
new-repo-test
- On my local version of the forked repo I did
git remote set-url origin http://repo-link.com/new-repo-test.git
- On my local version of the forked repo I did
git push origin master
- Verified that all of the changes that I wanted showed up in
new-repo-test
- Deleted
old-repo
- Renamed
new-repo-test
toold-repo
- NOTE: I had to update my remote to point to newly renamed repo using
git remote set-url origin http://repo-link.com/old-repo.git
. For
everybody else it would work without having to update origin url, but all of the remote branched would be removed. If you want to preserve remote branches, check them out to your local directory first and then push your new repo to git usinggit push --all origin
Faster Approach
I haven’t tested it, but in theory same results can be accomplished by just:
- Deleting old repo
- Creating new repo with the same name
- Pushing local version, which will automatically will be placed into the new repo that was created, replacing the old repo
Solution for GitHub
I tested a similar approach on GitHub. If you want to have a version of a repo without fork reference, simply create new personal repo on GitHub, update your remote origin url (step 2 above) and push your repo. Beware, that you will lose GitHub wiki and any other GitHub specific meta data associate with the forked repo.
Conclusion
In conclusion, in ideal world people would only fork repos when they intended to sync with them and crate new repos otherwise. That being said, if you happened to fork a repo and don’t care about tracking it anymore, but you do want to save your local history, hopefully the steps outlined above will help.