简体   繁体   English

如何将文件上传到Github存储库?

[英]How can I upload a file to the Github repository?

I have a public Github repository and some files to upload in my local computer. 我有一个公共Github存储库和一些要在我的本地计算机上传的文件。 Using Git Bash, I ran 'git init' at the same folder that the files are located. 使用Git Bash,我在文件所在的同一文件夹中运行'git init'。 I also added those files using 'git add' command. 我还使用'git add'命令添加了这些文件。 Please let me know what I should do next. 请让我知道下一步该做什么。 I don't know how to 'link' the local git folder and Github repository online. 我不知道如何在线“链接”本地git文件夹和Github存储库。

If you were able to git add the files, git push should push them to your repository on GitHub. 如果你能够git add文件, git push应该将它们推送到GitHub上的存储库。 For your first commit, you may need to git push origin master . 对于第一次提交,您可能需要git push origin master

EDIT: Before you can push, you'll also need to commit the files. 编辑:在你推动之前,你还需要提交文件。 You can do so with git commit -m "MESSAGE" where MESSAGE is a brief description of what you did like "Initial import of project" or "Added files". 您可以使用git commit -m "MESSAGE"来完成此操作,其中MESSAGE是您对“项目的初始导入”或“已添加文件”所做操作的简要说明。

Assuming you have already done the following: 假设您已经完成以下操作:

  • git init git init
  • git add -A git add -A
  • git commit -m "Initial code import" git commit -m“初始代码导入”

You now setup the remote to GitHub so you can push your local branch to GitHub. 您现在将远程设置为GitHub,以便将本地分支推送到GitHub。

To quote GitHub: 引用GitHub:

To connect your local repository to your GitHub account, you will need to set a remote for your repository and push your commits to it. 要将本地存储库连接到GitHub帐户,您需要为存储库设置一个远程并将提交推送到它。

$ git remote add origin https://github.com/username/Hello-World.git $ git remote add origin https://github.com/username/Hello-World.git

# Creates a remote named "origin" pointing at your GitHub repository #创建一个名为“origin”的远程指向您的GitHub存储库

$ git push origin master $ git push origin master

# Sends your commits in the "master" branch to GitHub #将您在“master”分支中的提交发送到GitHub

Here is the Create A Repo help guide that I quoted from. 这是我引用的Create A Repo帮助指南。

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

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