简体   繁体   中英

Push local repository to remote in Github

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

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM