How to disconnect a local Git repository from remote master
Asked Answered
E

5

95

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?

Epiphyte answered 11/4, 2015 at 22:16 Comment(1)
possible duplicate of how to remove remote origin from git repoTapir
B
151

git remote rm origin should work.

Brecciate answered 11/4, 2015 at 22:19 Comment(3)
I tried this but getting error fatal: No such remote: 'origin' What is origin here ?Threefold
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.Merrileemerrili
@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.Jumada
I
22

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

Indecency answered 16/7, 2015 at 4:37 Comment(0)
H
13

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

rm -rf path/to/local_repo/.git
Hasty answered 13/3, 2020 at 19:33 Comment(5)
By removing the '.git' folder, you will loose all history, branches, tags, stashes and submodules though.. Not always preferred..Rik
True. I suppose if you wanted to keep all that, could you just change the name of the .git folder?Hasty
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..Rik
If I want to untrack all the files what should I do ?Verona
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.Phytogenesis
L
1

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.

Lowspirited answered 23/5, 2023 at 2:15 Comment(0)
A
-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://mcmap.net/q/222891/-how-to-disconnect-a-local-git-repository-from-remote-master
Arlyn answered 29/1, 2023 at 17:55 Comment(1)
"i have a remote branch called swing-of-memories to" A remote is not a branch. In any case this just repeats existing answers.Dogmatism

© 2022 - 2024 — McMap. All rights reserved.