`git push` Without Complaints

On my work computer, I can make a new git branch and push it up to GitHub with a simple git push. I don’t need to manually set or create the upstream branch. Not so on my home computer. At least not when working on my dotfiles repo. When I try to push up a new branch, I get this error:

fatal: The current branch new-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin new-branch

It didn’t take too long to figure out the problem. Somewhere along the line I’d renamed the default remote from origin to github. I saw this by looking at the repo’s .git/.gitconfig file, which had the following lines:

[remote "github"]
    url = git@github.com:erikphansen/bin.git
    fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
    remote = github
    merge = refs/heads/master

I changed github to origin on the first and fifth lines, so it read:

[remote "origin"]
    url = git@github.com:erikphansen/bin.git
    fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

After that, no more complaints when trying to push up a branch that didn’t yet exist on GitHub.

I’m pretty sure that tomorrow’s post will be a follow up explaining how I could keep my remote branch named github and still allow for auto-creation of remote branches. Stay tuned for that excitement.

P.S. You might also need to check the value of git’s push.default setting with $ git config --global push.default. It it’s not current, then run git config --global push.default current. In my case, this was already set, but I don’t believe it’s like this out of the box.

Leave a Reply

Your email address will not be published. Required fields are marked *