简体   繁体   English

将文件从Web服务器上传到GitHub

[英]Upload files from webserver to GitHub

I was wondering if it is possible to, via git, copy files from my webserver to my GitHub repo to start editing it with github? 我想知道是否可以通过git将文件从我的Web服务器复制到我的GitHub存储库以开始使用github编辑它?

Thanks 谢谢

If you mean you want to copy the files directly from your webserver to GitHub, then no, that is not possible with git alone. 如果您想将文件直接从Web服务器复制到GitHub,则不能,仅使用git不可能。 While you could do it with some fairly straightforward shell scripting, I recommend that you try it manually for now. 尽管您可以使用一些相当简单的Shell脚本来完成此操作,但我建议您暂时手动尝试一下。

First, create a new repository on GitHub - the following documentation will walk you through this: https://help.github.com/articles/create-a-repo/ . 首先,在GitHub上创建一个新的存储库-以下文档将引导您完成此过程: https : //help.github.com/articles/create-a-repo/

Then you can clone it to your computer! 然后,您可以将其克隆到您的计算机上! - https://help.github.com/articles/cloning-a-repository/ -https://help.github.com/articles/cloning-a-repository/

Download a copy of your current webserver files - your html, css, js (if any), images, etc, the whole shebang, but make sure you don't have any passwords or other secrets in there. 下载您当前的Web服务器文件的副本-您的html,css,js(如果有),图像等,整个文件都保存下来,但请确保其中没有密码或其他秘密。

Copy your webserver files into the folder that was created when you cloned the repository. 将您的Web服务器文件复制到克隆存储库时创建的文件夹中。

Now, you need to add your files to the "index" (also called the staging area or cache), and then commit them to the repository. 现在,您需要将文件添加到“索引”(也称为暂存区或缓存),然后将它们提交到存储库。 To do this, open a terminal, cd to the cloned repository folder, and then run: 为此,打开一个终端, cd到克隆的存储库文件夹,然后运行:

git commit -am 'Initial Commit'

Lastly, push your changes to GitHub: 最后,将您的更改推送到GitHub:

git push

Done! 完成! (but read below...) (但请在下面阅读...)

I suggest having a look at GitHub Pages https://help.github.com/articles/what-is-github-pages/ . 我建议看看GitHub Pages https://help.github.com/articles/what-is-github-pages/ If you used GitHub Pages, each time you git push your new changes to GitHub, the website will update automatically. 如果您使用的是GitHub Pages,则每次git push新更改git push送到GitHub时,网站都会自动更新。 Whereas if you follow my answer above, you will need to reupload your website to your webserver each time you want it to update. 而如果您按照我的上述回答,则每次需要更新网站时,都需要将其重新上传到您的网络服务器。

A note about editing files on GitHub: 关于在GitHub上编辑文件的说明:

While GitHub has a great text editor inbuilt into their web interface, I only use it for simple changes - to correct spelling mistakes, grammar, etc. When you want to make changes to HTML, CSS, or code in general, it is best to use a text editor designed for coding (like Atom ) on your computer, and then push the changes to GitHub with git push . 尽管GitHub在其Web界面中内置了出色的文本编辑器,但我仅将其用于简单的更改-纠正拼写错误,语法等。当您想对HTML,CSS或代码进行总体更改时,最好使用专为在计算机上编码(例如Atom )而设计的文本编辑器,然后使用git push将更改推送到GitHub。

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

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