Changing the Git remote 'push to' default

后端 未结 11 1894
失恋的感觉
失恋的感觉 2020-12-04 05:35

I want to change the Git default remote branch destination so I could just

git push

Instead of:

git push upstream


        
相关标签:
11条回答
  • 2020-12-04 06:09

    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.

    0 讨论(0)
  • 2020-12-04 06:11

    In my case, I fixed by the following: * run git config --edit * In the git config file:

    [branch "master"]
    remote = origin # <--- change the default origin here
    
    0 讨论(0)
  • 2020-12-04 06:12

    Very simply, and cobbling together some of the great comments here along with my own research into this.

    First, check out the local branch you want to tie to your remote branch:

    git checkout mybranch
    

    Next:

    git branch -u origin/mybranch
    

    where:

    git branch -u {remote name}/{branch name}
    

    You should get a message:

    "Branch mybranch set up to track remote branch mybranch from origin."
    
    0 讨论(0)
  • 2020-12-04 06:13

    Another technique I just found for solving this (even if I deleted origin first, what appears to be a mistake) is manipulating git config directly:

    git config remote.origin.url url-to-my-other-remote
    
    0 讨论(0)
  • 2020-12-04 06:15

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

    git push -u <remote_name> --all
    
    0 讨论(0)
提交回复
热议问题