Git removing upstream from local repository

156,776

Solution 1

Using git version 1.7.9.5 there is no "remove" command for remote. Use "rm" instead.

$ git remote rm upstream
$ git remote add upstream https://github.com/Foo/repos.git

or, as noted in the previous answer, set-url works.

I don't know when the command changed, but Ubuntu 12.04 shipped with 1.7.9.5.

edit: a few people seem to have run into a situation where they do not have an "upstream" remote. execute cat .git/config and look at the name of the remote(s). (if on windows and not using powershell you can use type .git/config.)

the output will show the remotes configured for your git repo, e.g.,

[remote "origin"]

substitute the name of the remote you wish to remove as:

$ git remote rm origin

if you don't have the "upstream" remote, you can't remove it.

Solution 2

git remote manpage is pretty straightforward:

Use

Older (backwards-compatible) syntax:
$ git remote rm upstream
Newer syntax for newer git versions: (* see below)
$ git remote remove upstream

Then do:    
$ git remote add upstream https://github.com/Foo/repos.git

or just update the URL directly:

$ git remote set-url upstream https://github.com/Foo/repos.git

or if you are comfortable with it, just update the .git/config directly - you can probably figure out what you need to change (left as exercise for the reader).

...
[remote "upstream"]
    fetch = +refs/heads/*:refs/remotes/upstream/*
    url = https://github.com/foo/repos.git
...

===

* Regarding 'git remote rm' vs 'git remote remove' - this changed around git 1.7.10.3 / 1.7.12 2 - see

https://code.google.com/p/git-core/source/detail?spec=svne17dba8fe15028425acd6a4ebebf1b8e9377d3c6&r=e17dba8fe15028425acd6a4ebebf1b8e9377d3c6

Log message

remote: prefer subcommand name 'remove' to 'rm'

All remote subcommands are spelled out words except 'rm'. 'rm', being a
popular UNIX command name, may mislead users that there are also 'ls' or
'mv'. Use 'remove' to fit with the rest of subcommands.

'rm' is still supported and used in the test suite. It's just not
widely advertised.

Solution 3

$ git remote remove <name>

ie.

$ git remote remove upstream

that should do the trick

Solution 4

In git version 2.14.3,

You can remove upstream using

git branch --unset-upstream

The above command will also remove the tracking stream branch, hence if you want to rebase from repository you have use

git rebase origin master 

instead of git pull --rebase

Share:
156,776

Related videos on Youtube

user2603138
Author by

user2603138

Updated on June 30, 2021

Comments

  • user2603138
    user2603138 almost 3 years

    I am working with a ruby on rails application and I am trying to sync a fork. It is worth mentioning that I am also on a Mac. I committed the following action:

    $ git remote -v
    

    to get a view of my local repository. I messed up when trying to go upstream:

    $ git remote add upstream https://github.com/foo/repo.git
    

    When I should have capitalized Foo:

    $ git remote add upstream https://github.com/Foo/repos.git
    

    The question is how do I remove the upstream because every time I try and change this it comes back with creating a fatal error?

  • Michael Scheper
    Michael Scheper almost 10 years
    This answer seems to require updating. In git 1.7.9, git remote remove upstream produces 'error: Unknown subcommand: remove'
  • Jason
    Jason almost 5 years
    This worked perfectly for my branch with 2 different upstreams
  • Guy
    Guy almost 3 years
    On Windows, it returns the error usage: git remote remove <name> but doesn't remove the upstream.
  • bmacnaughton
    bmacnaughton almost 3 years
    it returns that when you execute git remote rm upstream? thanks - i don't use windows much for development.
  • user1709076
    user1709076 almost 3 years
    fatal: No such remote: 'upstream'
  • user1709076
    user1709076 almost 3 years
    'git remote rm master' gives me "fatal: No such remote: 'master'"
  • bmacnaughton
    bmacnaughton almost 3 years
    try 'git remote rm upstream`
  • moudug
    moudug almost 2 years
    This answer seems the good one in 2022