How to Remove Origin from Git Repository

How to Remove Origin from Git Repository

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.

4 Answers

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
1

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
0

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: 
 * [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: 
  Push  URL: 
  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!

Use this> git show origin > git remote rm origin

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.