How do I change the remote a git branch is tracking?

The central repository had to be set up on a new server, so I created a new remote on my local repo, and pushed to that.

But now when I do git pull, it claims I am up to date. It’s wrong—it’s telling me about the old remote branch, not the new one, which I know for a fact has new commits to fetch.

  • Git command to unstage all new files (unstage by status)
  • git clone --recursive fails
  • Setting default diff algorithm does not translate to default merge algorithm (patience)
  • In a git merge, how do you just replace your version with the version git says there is a conflict with?
  • Git stopped working on Android studio
  • Reapply commits while ignoring all space changes with Git
  • How do I change my local branch to track a different remote?

    I can see this in the git config file but I don’t want to mess things up.

    [branch "master"]
        remote = oldserver
        merge = refs/heads/master

  • deleted commits after git push force
  • Git: Accidentally reverted without commiting
  • Bundler: always use latest revision of git branch in Gemfile
  • How to merge two branches that are too much different from each other in git
  • git: move commit before merge
  • Clear my master branch and send a clean pull request
  • 8 Solutions collect form web for “How do I change the remote a git branch is tracking?”

    Without deleting anything, using git v1.8.0 or later:
    git branch branch_name --set-upstream-to your_new_remote/branch_name

    Or you can use the -u switch:
    git branch branch_name -u your_new_remote/branch_name

    Using git up to v1.7.12:
    git branch --set-upstream branch_name your_new_remote/branch_name

    For me the fix was:

    git remote set-url origin https://some_url/some_repo


    git push

    If you’re sane about it, editing the config file’s safe enough. If you want to be a little more paranoid, you can use the porcelain command to modify it:

    git config branch.master.remote newserver

    Of course, if you look at the config before and after, you’ll see that it did exactly what you were going to do.

    But in your individual case, what I’d do is:

    git remote rename origin old-origin
    git remote rename new-origin origin

    That is, if the new server is going to be the canonical remote, why not call it origin as if you’d originally cloned from it?

    With an up to date git (2.5.5) the command is the following :

    git branch --set-upstream-to=origin/branch

    This will update the remote tracked branch for your current local branch

    Another option to have a lot of control over what’s happening is to edit your configurations by hand:

    git config --edit

    or the shorthand

    git config -e

    Then edit the file at will, save and your modifications will be applied.

    You could either delete your current branch and do:

    git branch --track local_branch remote_branch

    Or change change remote server to the current one in the config

    git fetch origin
    git checkout --track -b local_branch_name origin/branch_name


    git fetch
    git checkout -b local_branch_name origin/branch_name

    Based on what I understand from the latest git documentation, the synopsis is:

    git branch -u upstream-branch local-branch
    git branch --set-upstream-to=upstream-branch local-branch

    This usage seems to be a bit different than urschrei’s answer, as in his the synopsis is:

    git branch local-branch -u upstream-branch 
    git branch local-branch --set-upstream-to=upstream-branch 

    I’m guessing they changed the documentation again?

    Git Baby is a git and github fan, let's start git clone.