Alex Reds
Alex Reds

Reputation: 307

git push error: the requested URL returned error 400

I am new to Git and I am trying to to push a Java project to Github using Git Bash.

This is what I did:

But when I do the push, this is the result I get:

fatal: unable to access 'https://github.com/username/repository/': The requested URL returned error: 400

I read somewhere this is could be a login problem, but I checked my config in GitBash and the username and email match with GitHub. When I commit the push, I I am logged in to my GitHub account and I do not receive any insert password request from GitBash.

Then I tried to push the project directly from Eclipse, but this failed as well, in fact when I push the changes I receive the message: - master >> master [rejected - non-fast-forward]

I am totally lost, I think all the step are correct however it looks like my local and remote repositories don't want to talk to each other, and I have no idea why.

Any help?

Upvotes: 11

Views: 54958

Answers (4)

Awesome
Awesome

Reputation: 388

Had a similar problem and it turned out that I had some issues with my .gitconfig file since I had earlier run git config --global url."[email protected]:".insteadOf "https://github.com/" and later git config --global url."https://github.com/".insteadOf "[email protected]:" which added both lines to my .gitconfig file. So all I did was clean my .gitconfig file using vim in my terminal(Iterm) :

$ vi $HOME/.gitconfig

Then removed the unwanted lines from the .gitconfig file using vim editor. Hope it helps.

Upvotes: 2

m000
m000

Reputation: 6087

You missed the .git part, which is important. The url you are adding corresponds to the web page you view on GitHub, not the git repository. You should do:

$ git remote add origin https://github.com/alerossi82/Blog.git

Also, if this is your own repository, you probably want to use the SSH url instead of the HTTPS url: $ git remote add origin [email protected]:alerossi82/Blog.git

This will make your everyday life easier, as you can use an ssh key for authentication instead of typing your GitHub password every time. More info on GitHub urls here.

Upvotes: 0

Farhad
Farhad

Reputation: 12976

You should fist check what files, you have changes and are ready to be committed, using :

git status

If you saw any changed files, stage them for committing, using :

git add .

Then commit your changes.

git commit -m "your commit message"

And finally :

git push -u origin master

Upvotes: 0

CodeWizard
CodeWizard

Reputation: 142064

You missed the

 git add . -A

before the commit so no files were added


cd C:/Users/Alessandro/workspace/BLOG
echo "# Blog" >> README.md

# Here you need to run the git add command 
git add -A .

git commit -m "Initial commit"
git remote add origin https://github.com/alerossi82/Blog
git push -u origin master

Upvotes: 0

Related Questions