我在GitHub上创建了一个帐户,我面临着添加文件的问题。我已经添加了readme.txt。此外,我还有3个其他PHP文件和一个文件夹,包括图像。

如何添加文件和文件夹?我尝试用git pull,因为git push origin -u master显示了一个错误。


当前回答

我明白你的意思。

拖放功能的解决方案可能不复存在。当发生这种情况时,请参阅下面的链接: https://www.reddit.com/r/github/comments/meuxtg/github_drag_and_drop_not_working/

如果有人想要避免shell和所有命令,并希望有一个UI来做到这一点,Github桌面是前进的一种方式。

安装和使用Github Desktop的步骤:

我假设你知道本地回购和远程回购之间的区别

Install Github Desktop Create a repository locally on your hard drive by using github desktop. This will automatically create files like .git and .gitattributes. It also asks to create a README.md file, always best practice is to create it and edit it informing readers about your project overview, installation steps etc. README.md is rendered in Markdown and can also render HTML. See more about Markdown here: Markdown Cheatsheet guide Copy and Paste all the folders and files that you want to upload(basically the right terminology is "Push" ) into this newly created local repository. Be aware of the directory structure as the exact same directory structure will be replicated on your remote repository. Go to github desktop, as soon as you paste files in the local repo, you will see them as changes here. All you need to do is commit these changes with a comment. This will be your "First or Initial Commit" to the repo. Next Github repo will ask whether you want to publish these to its remote repository. Click "Publish" Note Publish is just a one time operations. Going forward any further changes you make to local repo will be seen in github desktop and you need to again follow the loop of "Commit local->Fetch from remote->Push to Remote. As long as you are the only developer working on a project you need not go into other mechanics of git branches etc. To verify if your repo is published remotely login to your github profile on the web and see your repository sitting there. This your remote repo which you effectively created from your local repo by using Github desktop.

其他回答

我在Windows上使用VS SSDT。我开始了一个项目,并设置了本地版本控制。后来我安装了git,并创建了一个Github repo。一旦我在Github上有我的回购,我抓住了URL,当我点击“发布到Github”按钮时,它问我的URL时,我把它放进了VS。

点击这里查看我的答案:https://stackoverflow.com/a/50039345/2647919

或者,甚至更好的只是“拖放”文件夹,在git浏览器中打开你的存储库。

在web门户中打开您的存储库,您将看到所有文件的列表。如果您最近刚刚创建了repo,并使用README初始化,那么您将只看到README清单。

打开你想要上传的文件夹。在浏览器中拖放列表。请看这里的图片。”

您需要将存储库签出到本地机器上。然后您可以在本地机器上更改该文件夹。

git commit -am "added files"

该命令将所有文件提交到repo。

git push origin master

它将把你的主分支(我假设是你正在使用的)中的所有更改推到远程存储库起源(在这种情况下,github)

Linux和MacOS用户:

首先在github上创建存储库(Name=RepositoryName)。 打开终端并创建新目录(mkdir NewDirectory)。 复制你的ProjectFolder到这个NewDirectory。 将当前工作目录更改为NewDirectory。 运行这些命令 git init git添加ProjectFolderName Git commit -m "第一次提交" git远程添加origin https://github.com/YourGithubUsername/RepositoryName.git Git push -u origin master

更改目录到主文件夹。然后“git add .”命令就可以工作了。