How to remove origin from git repository

GitGit Svn

Git Problem Overview


Basic question: How do I disassociate a git repo from the origin from which it was cloned?

git branch -a shows:

* master
  remotes/origin/HEAD -> origin/master

and I want to remove all knowledge of origin, and the associated revisions.

Longer question: I want to take an existing subversion repo and make a number of smaller git repos from it. Each of the new git repos should have the full history of just the relevant branch. I can prune the repo to just the wanted subtree using:

git filter-branch --subdirectory-filter path/to/subtree HEAD

but the resulting repo still contains all the revisions of the now-discarded subtrees under the origin/master branch.

I realise that I could use the -T flag to git-svn to clone the relevant subtree of the subversion repo in the first place. I'm not sure if that would be more efficient than later running multiple instantiations of git filter-branch --subdirectory-filter on copies of the git repo but, in any case, I would still like to break the link with the origin.

Git Solutions


Solution 1 - Git

Fairly straightforward:

git remote rm origin

As for the filter-branch question - just add --prune-empty to your filter branch command and it'll remove any revision that doesn't actually contain any changes in your resulting repo:

git filter-branch --prune-empty --subdirectory-filter path/to/subtree HEAD

Solution 2 - Git

Remove existing origin and add new origin to your project directory

>$ git remote show origin

>$ git remote rm origin

>$ git add .

>$ git commit -m "First commit"

>$ git remote add origin Copied_origin_url

>$ git remote show origin

>$ git push origin master

Solution 3 - Git

In my case git branch -r would keep showing origin/master on the local repository (after I renamed master on remote and local)

This fixed it:

E:\SourceCode\PascalCoinGit\PascalCoin>git remote prune origin
Pruning origin
URL: https://github.com/SkybuckFlying/PascalCoin
 * [pruned] origin/master

E:\SourceCode\PascalCoinGit\PascalCoin>

Command:

git remote show origin

(Seen it before but completely forgot about it)

Result:

E:\SourceCode\PascalCoinGit\PascalCoin>git remote show origin
* remote origin
  Fetch URL: https://github.com/SkybuckFlying/PascalCoin
  Push  URL: https://github.com/SkybuckFlying/PascalCoin
  HEAD branch: PascalCoinMaster
  Remote branches:
    GUIExperimentalBugFixes1       tracked
    GUIExperimentalBugFixes2       tracked
    GUIExperimentalBugFixes3       tracked
    GUIExperimentalBugFixes4       tracked
    GUIExperimentalBugFixes5       tracked
    MergeTest                      tracked
    PIP-0026Windows7Implementation tracked
    PascalCoinMaster               tracked
    SkybuckMaster                  tracked
    TestPascalCoinMaster           tracked
    refs/remotes/origin/master     stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    GUIExperimentalBugFixes1       merges with remote GUIExperimentalBugFixes1
    GUIExperimentalBugFixes2       merges with remote GUIExperimentalBugFixes2
    GUIExperimentalBugFixes4       merges with remote GUIExperimentalBugFixes4
    GUIExperimentalBugFixes5       merges with remote GUIExperimentalBugFixes5
    MergeTest                      merges with remote MergeTest
    PIP-0026Windows7Implementation merges with remote PIP-0026Windows7Implementation
    SkybuckMaster                  merges with remote SkybuckMaster
  Local refs configured for 'git push':
    GUIExperimentalBugFixes1       pushes to GUIExperimentalBugFixes1       (up to date)
    GUIExperimentalBugFixes2       pushes to GUIExperimentalBugFixes2       (up to date)
    GUIExperimentalBugFixes3       pushes to GUIExperimentalBugFixes3       (up to date)
    GUIExperimentalBugFixes4       pushes to GUIExperimentalBugFixes4       (up to date)
    GUIExperimentalBugFixes5       pushes to GUIExperimentalBugFixes5       (up to date)
    MergeTest                      pushes to MergeTest                      (up to date)
    PIP-0026Windows7Implementation pushes to PIP-0026Windows7Implementation (fast-forwardable)
    PascalCoinMaster               pushes to PascalCoinMaster               (up to date)
    SkybuckMaster                  pushes to SkybuckMaster                  (up to date)
    TestPascalCoinMaster           pushes to TestPascalCoinMaster           (up to date)

E:\SourceCode\PascalCoinGit\PascalCoin>

Yup, git branch -r now shows it's gone!

Solution 4 - Git

Use this> git show origin > git remote rm origin

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionawyView Question on Stackoverflow
Solution 1 - GitAmberView Answer on Stackoverflow
Solution 2 - GitMandeep Singh GillView Answer on Stackoverflow
Solution 3 - GitoOoView Answer on Stackoverflow
Solution 4 - GitIsmail Ashari SambaraView Answer on Stackoverflow