65

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?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Cerin
  • 55,951
  • 85
  • 291
  • 487
  • 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

3 Answers3

106

git remote rm origin should work.

helion3
  • 30,779
  • 15
  • 51
  • 95
  • 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
11

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,527
  • 2
  • 12
  • 16
6

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

rm -rf path/to/local_repo/.git
DanGoodrick
  • 2,410
  • 5
  • 25
  • 48
  • 10
    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
  • 4
    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