87

How do I completely disconnect a local Git repository from all remote branches?

I cloned a Git repository from github.com, but then it was deleted and I don't want Git to report any changes needing to be "pushed up". I've tried googling this, but I think my terminology is wrong, and I'm not finding anything.

Can I simply delete the [remote "origin"] and [branch "master"] sections from my .git/config file or will that break my local repository?

bitski
  • 1,168
  • 1
  • 13
  • 20
Cerin
  • 60,957
  • 96
  • 316
  • 522
  • possible duplicate of [how to remove remote origin from git repo](http://stackoverflow.com/questions/16330404/how-to-remove-remote-origin-from-git-repo) – Andrew C Apr 11 '15 at 23:32

5 Answers5

139

git remote rm origin should work.

helion3
  • 34,737
  • 15
  • 57
  • 100
  • 1
    I tried this but getting error `fatal: No such remote: 'origin'` What is origin here ? – javaGroup456 Oct 22 '19 at 06:18
  • If you cloned the project - then this should work. If it is local project you created - there is a chance it is currently not connected to remote repo. – Alexey Shevelyov Nov 05 '19 at 21:16
  • @javaGroup456, (I'm a little late to this question, but still) you can list your remotes with `git remote` or `git remote -v` to get the urls after the names. Then, you can remove any of the remotes listed, using the above command. – Alexandar Zaharyan Jan 12 '21 at 10:10
20

This works:

To remove a remote: git remote remove origin

To add a remote: git remote add origin yourRemoteUrl & then git push -u origin master

Vontei
  • 1,727
  • 2
  • 14
  • 16
12

If you remove the .git folder, it will disconnect your local repo from the remote.

rm -rf path/to/local_repo/.git
DanGoodrick
  • 2,818
  • 6
  • 28
  • 52
  • 11
    By removing the '.git' folder, you will loose all history, branches, tags, stashes and submodules though.. Not always preferred.. – jo.On Apr 28 '20 at 15:25
  • True. I suppose if you wanted to keep all that, could you just change the name of the .git folder? – DanGoodrick May 02 '20 at 12:59
  • 5
    by running "git remote rm origin", you will just remove the connection from your repo to the remote origin without losing all history, branches, tags and stashes you had locally.. It would then for example be possible to connect to a different (ideally empty) remote and push everything to that one.. – jo.On May 05 '20 at 12:45
  • If I want to untrack all the files what should I do ? – vikramvi Sep 15 '20 at 07:39
  • 1
    This is the answer if you want to remove all the history and just start fresh with a pile of files. The other answers will retain the git history but not be connected with the repo from which you cloned/fetched the repo. It's unclear from the post if they are trying to remove the history entirely or (what I suspect) just stop being bugged by `git` about changes that haven't been pushed to the origin. So maybe they are(were) looking for one of the answers below. – mr rogers Feb 03 '23 at 06:37
0

For me using Windows OS, I just rename the hidden file .git as .git[delete]
Then the connection to the repository is broken.

After that if I need to restore it, I could rename it back to .git.
So I will not loose all history, branches, tags, stashes, submodules, etc.

Sy.Yah
  • 25
  • 6
-1

for example i have a remote repository called swing-of-memories to disconnect/remove the remote repository

git remote remove swing-of-memories

to see the list of all branch local/remote

reference https://www.nobledesktop.com/learn/git/git-branches

git branch -a

to add an existing remote repository there is already made answer above on this

https://stackoverflow.com/a/31445446/13294261
KaZaiya
  • 59
  • 6
  • "i have a remote branch called swing-of-memories to" A remote is _not_ a branch. In any case this just repeats existing answers. – matt Jan 29 '23 at 18:01