Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the Git remote 'push to' default

People also ask

What is git push default?

Defines the action git push should take if no refspec is explicitly given. Possible values are: nothing – do not push anything (error out) unless a refspec is explicitly given.

How do I set push origin?

Run the git remote set-url --add --push origin git-repository-name command where git-repository-name is the URL and name of the Git repository where you want to host your code. This changes the push destination of origin to that Git repository.

How do I change my git remote?

In order to change the URL of a Git remote, you have to use the “git remote set-url” command and specify the name of the remote as well as the new remote URL to be changed.


You can use git push -u <remote_name> <local_branch_name> to set the default upstream. See the documentation for git push for more details.


To change which upstream remote is "wired" to your branch, use the git branch command with the upstream configuration flag.

Ensure the remote exists first:

git remote -vv

Set the preferred remote for the current (checked out) branch:

git branch --set-upstream-to <remote-name>

Validate the branch is setup with the correct upstream remote:

git branch -vv


Working with Git 2.3.2 ...

git branch --set-upstream-to myfork/master

Now status, push and pull are pointed to myfork remote


You can easily change default remote for branches all at once simply using this command

git push -u <remote_name> --all

If you did git push origin -u localBranchName:remoteBranchName and on sequentially git push commands, you get errors that then origin doesn't exist, then follow these steps:

  1. git remote -v

Check if there is any remote that I don't care. Delete them with git remote remove 'name'

  1. git config --edit

Look for possible signs of a old/non-existent remote. Look for pushdefault:

[remote]
  pushdefault = oldremote

Update oldremote value and save.

git push should work now.


It might be helpful to take a look at .git/config inside your repo, it will list all remotes and also the default remote for each branch

eg.

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = [email protected]:fii/web2016.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "bugfix/#8302"]
    remote = origin
    merge = "refs/heads/bugfix/#8302"
[branch "feature/#8331"]
    remote = origin
    merge = "refs/heads/feature/#8331"
[remote "scm"]
    url = https://scm.xxx.be/git/web2016bs.git
    fetch = +refs/heads/*:refs/remotes/scm/*

you can make manual changes in this file to remove an unwanted remote, or update the default remotes for the different branches you have

  • Pay attention! when changing or removing the remotes make sure to update all references to it in this config file