我在GitHub上创建了一个帐户,我面临着添加文件的问题。我已经添加了readme.txt。此外,我还有3个其他PHP文件和一个文件夹,包括图像。
如何添加文件和文件夹?我尝试用git pull,因为git push origin -u master显示了一个错误。
我在GitHub上创建了一个帐户,我面临着添加文件的问题。我已经添加了readme.txt。此外,我还有3个其他PHP文件和一个文件夹,包括图像。
如何添加文件和文件夹?我尝试用git pull,因为git push origin -u master显示了一个错误。
当前回答
注意,从2012年12月初开始,你可以直接从GitHub创建新文件:
ProTip™:您可以只使用URL预填充文件名字段。 在URL的末尾输入?filename=yournewfile.txt,将文件名字段预先填充为yournewfile.txt。
其他回答
我明白你的意思。
拖放功能的解决方案可能不复存在。当发生这种情况时,请参阅下面的链接: 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.
你可以使用git add,例如git add README, git add <folder>/*,甚至git add *来添加文件
然后使用git commit -m "<Message>"来提交文件
最后git push -u origin master来推送文件。
当你做修改时,运行git status,它会给你修改的文件列表,使用git add *添加它们,或者你可以单独指定每个文件,然后git commit -m <message>,最后,git push -u origin master
例如,你创建了一个文件README,运行git状态给你
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README
运行git add README,文件被暂存提交。然后再次运行git status,它会给你一个结果——文件已经添加完毕,可以提交了。
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: README
#
nothing added to commit but untracked files present (use "git add" to track)
然后运行git commit -m 'Added README'
$ git commit -m 'Added README'
[master 6402a2e] Added README
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
最后,git push -u origin master来推送存储库起源的远程分支master。
$ git push -u origin master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 267 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To xxx@xxx.com:xxx/xxx.git
292c57a..6402a2e master -> master
Branch master set up to track remote branch master from origin.
文件已经成功地推送到远程存储库。
运行git pull origin master以确保你已经吸收了所有上游的更改
$ git pull origin master
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 4), reused 7 (delta 3)
Unpacking objects: 100% (8/8), done.
From xxx.com:xxx/xxx
* branch master -> FETCH_HEAD
Updating e0ef362..6402a2e
Fast-forward
public/javascript/xxx.js | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
create mode 100644 README
如果您不想将上游的更改与本地存储库合并,请运行git fetch来获取更改,然后运行git merge来合并更改。Git pull只是fetch和merge的组合。
我个人使用gitimmersion - http://gitimmersion.com/来了解git,如果你需要一些文档和帮助,这是一个循序渐进的指南
如果你想添加一个空文件夹,你可以添加一个'。把文件放在你的文件夹里。
这是因为git并不关心文件夹。
简单的解决方案:
git init
git add =A
git commit -m "your commit"
git push -u origin master
如果你想添加文件夹到现有的repo ..然后将文件夹添加到本地项目代码
git rm --cached ./folderName
git add ./folderName
在那之后
git status
git commit -m "your commit"
git push -u origin master
您需要将存储库签出到本地机器上。然后您可以在本地机器上更改该文件夹。
git commit -am "added files"
该命令将所有文件提交到repo。
git push origin master
它将把你的主分支(我假设是你正在使用的)中的所有更改推到远程存储库起源(在这种情况下,github)