简体   繁体   English

在Github中将本地存储库推送到远程

[英]Push local repository to remote in Github

I have a java project that contains one java file called Calculator. 我有一个Java项目,其中包含一个名为Calculator的Java文件。 I created a repository in Github and I tried to push the local repository to the remote one by following: 我在Github中创建了一个存储库,并尝试通过以下操作将本地存储库推送到远程存储库:

First: I created a readme file echo "# Simple Java calculator" >> README.md 首先:我创建了一个自述文件echo "# Simple Java calculator" >> README.md

Second: git init 第二: git init

Third: git add README.md 第三: git add README.md

Fourth: git commit -m "simple calculator" 第四: git commit -m "simple calculator"

Fifth: git remote add origin https://github.com/XXXXX/Calc.git 第五: git remote add origin https://github.com/XXXXX/Calc.git

Sixth: git push -u origin master 第六名: git push -u origin master

After that I checked the repository online and I only found the Read me file. 之后,我在线检查了存储库,并且只找到了Read me文件。 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. Git使用add将文件添加到索引。 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 由于尚未提交,因此需要输入git commit

after you've done a git add 完成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. 您在push命令中使用的-u告诉git master应该始终在原始位置将其推送到master,因此您只需要在第一次使用它。 From now on it should be enough for you to type: git push 从现在开始,您应该足以输入: git push

instead of git push -u origin master 代替git push -u origin master

After adding the files using, 使用添加文件后,

git add . git添加

You should commit the changes before pushing to the remote repo, 您应该先提交更改,然后再推送到远程仓库,

git commit -m "commit message" git commit -m“提交消息”

Also, you can use the below single command to add and commit, 另外,您可以使用以下单个命令添加和提交,

git commit -am "commit message" git commit -am“提交消息”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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