Reputation: 2140
I have a java project that contains one java file called Calculator. I created a repository in Github and I tried to push the local repository to the remote one by following:
First: I created a readme file echo "# Simple Java calculator" >> README.md
Second: git init
Third: git add README.md
Fourth: git commit -m "simple calculator"
Fifth: git remote add origin https://github.com/XXXXX/Calc.git
Sixth: git push -u origin master
After that I checked the repository online and I only found the Read me file. I later figured our I need to add the Calculator file and I tried the following options:
git add .
git push -u origin master
and this option
git add Calculator.java
git push -u origin master
but both did not work and the file is not in the remote repository yet. Can someone help me with this
Upvotes: 1
Views: 177
Reputation: 395
After adding the files using,
git add .
You should commit the changes before pushing to the remote repo,
git commit -m "commit message"
Also, you can use the below single command to add and commit,
git commit -am "commit message"
Upvotes: 1
Reputation: 24441
Git uses add to add files to the index. Then commit to commit the files in the index and then push to share your commits with another repository.
Since you've not made a commit, you need to type
git commit
after you've done a
git add
and before you do a
git push
The -u you use to the push command, tells git that master should always push to master on origin, so you just need to use that the first time. From now on it should be enough for you to type:
git push
instead of
git push -u origin master
Upvotes: 1