Although, I could commit my change locally, I can not push to origin master
I run
$ git remote add origin [email protected]:username/test.git
I get
fatal: remote origin already exists.
I run
$ git push -u origin master
I get
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly
What's wrong with this?
git push origin master will push your changes to the remote server. "master" refers to master branch in your repository. If you want to push your changes to any other branch (say test-branch), you can do it by: git push origin test-branch. This will push your code to origin of test-branch in your repository.
It may be possible that push permission is not provided to the user pushing the code changes. I suggest checking the user permissions. If the push permission is present, then it may be possible that there is a pre-push git hook in the repo and your push isn't in accordance with it.
Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch. Simply use a git push origin command on subsequent pushes of the new branch to the remote repo.
To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch).
2-way to do this
1st:-
git remote set-url <name> <newurl>
example:-
git remote set-url origin [email protected]:username/test.git
2nd:-
What you need to do is change your 'origin' setting.you edit .git/config in your project root, which may look something like this:
...
[remote "origin"]
url = git://[email protected]/git/repos/path
fetch = +refs/heads/*:refs/remotes/origin/*
...
or if your 'remote' is actually local:
...
[remote "origin"]
url = /path/to/repos/on/this/machine
fetch = +refs/heads/*:refs/remotes/origin/*
...
All you need to do is edit that file with your favorite editor and change the url = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll be happily pushing and pulling to and from your new remote location.
I know this question is older but I came across it while trying to find the answer for an error I was having and I found the answer. As of Oct 2020 any new repository created the branch will be called main and not master. GitHub is renaming the primary branch due to racism with master/slave properties. You will want to type git push orgin main.
It looks like there's a bad entry for origin
in your config file.
Edit your repository's .git/config
file to change it; the format is fairly self-explanatory, but post its contents if you have trouble.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With