6
votes

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:

  • created a Blog repository in GitHub

  • in Git Bash

    $ cd C:/Users/Alessandro/workspace/BLOG

    $ echo "# Blog" >> README.md

    $ git add –-all

    $ git commit -m "Initial commit"

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

    $ git push -u origin master

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?

4
Why have you added JAVA as one of the Tags? You might want to do a Pull first, make changes and then push it. - user2004685
ok, as I wrote I'm new to Git, but if I understood it well, a Pull is a request to propose to merge the changes in a branch into the master branch, is it correct? The fact is, I did not do any change to my project, therefore I did not create any alternative branch; I simply would like to pull all the files from my project to the remote repository in the master branch. Does it make sense or I am missing something? - Alex Reds
Pull Request won't come into picture if you are pushing your changes directly to the master branch. If you are working on a feature branch then you'll have to create a Pull request to merge it on to your develop/master branch. - user2004685

4 Answers

0
votes

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
0
votes

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
0
votes

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.

0
votes

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.