Reputation: 39268
The scenario is that I have no repos on the remote server, just an account. Then, I run locally the following commands, where x is the user name and y is the project name that only exists on my local system.
git init
git remote add buckety https://[email protected]/x/y.git
git add .
git commit --message "Here we go..."
git push buckety
Now I get the error urging me to set up the remote upstream. I can do that (either --set-upstream
or -u
) but according to my googlearching, it's been deprecated. (Actually weird that the suggestion in the console mentions it still.)
I want to do it the proper way and I've goolearched both --track
and --set-upstream-to
. However, there's no example for my particular scenario on Git as far I could see and the operations I've tested failed with errors.
How should I create the remote branch without retracting to using the deprecated option? I might want to create a tracking branch on remote so that:
Preferably, I'd like to configure it prior to the push but I'm not sure how. I can't use checkout because the branch doesn't exist yet. I can't use set-upstream-to for the same reason.
Upvotes: 10
Views: 16835
Reputation: 1329292
The right command is:
git push -u origin master
Or, for more recent (2021+) repositories:
git push -u origin main
Then the next git push
will be a simple: git push
.
See "Why do I need to explicitly push a new branch?"
Since Git 1.8, --set-upstream
is called --set-upstream-to
You can set up a remote tracking branch in advance with:
git branch -u origin/master master
# or
git branch -u origin/main main
(Then your first git push
would have been a simple git push
)
Upvotes: 11
Reputation:
As an addition to VonC's answer, if you find that it's pushing to the wrong remote branch, e.g. after you've renamed the master
branch to main
, try this:
git push -u origin main:main
Upvotes: 0
Reputation: 1562
For me pushing an existing local branch to a branch that doesn't (yet) exist on the server is:
git push --set-upstream origin LocalBranchThatDoesntExistOnServer
Upvotes: 2
Reputation: 842
That is how i push to gerrit instance without adding remote
git push http://localhost:8080/scm *:*
fatal: remote error: Git repository not found
But the project must exist already
Upvotes: 0