如何将文件和文件夹添加到GitHub仓库? [英] How do I add files and folders into GitHub repos?
问题描述
我在GitHub上创建了一个帐户—我是新手 - —而且我在添加文件时遇到问题。我已经添加了 readme.txt
。另外,我还有3个其他PHP文件和一个包含图像的文件夹。
如何添加文件和文件夹?我试着用 git pull
,因为 git push origin -u master
给我一个错误。
您可以使用 git add
添加文件,例如 git add README ,
git add< folder> / *
,甚至 git add *
然后使用 git commit -m< Message>
来提交文件。
b $ b
最后 git push -u origin master
推送文件。
git status
给你修改的文件列表,使用 git add *
添加它们,或者你可以指定每个然后 git commit -m< message>
,最后, git push -u origin master
示例 - 假设您创建了一个文件README,运行 git status
给您
$ git status
#分支大师
#未记录文件:
#(使用git添加< file> ...以包含将要提交的内容)
#
#README
运行 git add README
,这些文件将进行提交。然后再次运行 git status
,它会给你 - 文件已被添加并准备好提交。
$ git status
#在分支主机上
#要提交的更改:
#(使用git reset HEAD< file> ... )
#
新文件:自述文件
#
没有添加提交但未跟踪文件存在(使用git add跟踪)
然后执行 git commit -m'新增README'
$ git commit -m'已添加README'
[master 6402a2e]已添加README
0个文件已更改,0个插入(+),0删除( - )
创建模式100644自述文件
最后, git push -u origin master
来为存储库 origin $ c>推送远程分支
master
$ c $。
$ b $ pre $ git push -u origin master
计数对象:4,完成。
使用多达2个线程的增量压缩。
压缩对象:100%(2/2),完成。
写入对象:100%(3/3),267字节,完成。
合计3(增量1),重用0(增量0)
至xxx@xxx.com:xxx / xxx.git
292c57a..6402a2e master - > master
设置分支主设备以从原点跟踪远程分支主设备。
这些文件已成功推送到远程存储库。
运行一个 git pull origin master
以确保您吸收了任何上游更改
$ git pull origin master
remote:计数对象:12,完成。
remote:压缩对象:100%(4/4),完成。
remote:合计8(delta 4),重复使用7(delta 3)
开箱对象:100%(8/8),完成。
从xxx.com:xxx/xxx
*分支大师 - > FETCH_HEAD
更新e0ef362..6402a2e
快进
public / javascript / xxx.js | 5 ++ ---
1个文件已更改,2个插入(+),3个删除( - )
创建模式100644自述文件
如果您不想将上游更改与本地存储库合并,请运行 git fetch
来获取更改,然后执行 git merge
来合并更改。 git pull
只是 fetch
和 merge
的组合。
我个人使用过gitimmersion - http://gitimmersion.com/ 以获得git上的曲线,它是一步一步的指南,如果您需要一些文档和帮助
I created an account on GitHub — I'm new on it — and I'm facing a problem with adding files. I have added readme.txt
. Also, I have 3 other PHP files and a folder including images.
How do I add the files and folder? I tried it with git pull
because git push origin -u master
showed me an error.
You can add files using git add
, example git add README
, git add <folder>/*
, or even git add *
Then use git commit -m "<Message>"
to commit files
Finally git push -u origin master
to push files.
When you make modifications run git status
which gives you the list of files modified, add them using git add *
for everything or you can specify each file individually, then git commit -m <message>
and finally, git push -u origin master
Example - say you created a file README, running git status
gives you
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README
Run git add README
, the files are staged for committing. Then run git status
again, it should give you - the files have been added and ready for committing.
$ 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)
Then run 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
Finally, git push -u origin master
to push the remote branch master
for the repository origin
.
$ 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.
The files have been pushed successfully to the remote repository.
Running a git pull origin master
to ensure you have absorbed any upstream changes
$ 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
If you do not want to merge the upstream changes with your local repository, run git fetch
to fetch the changes and then git merge
to merge the changes. git pull
is just a combination of fetch
and merge
.
I have personally used gitimmersion - http://gitimmersion.com/ to get upto curve on git, its a step-by-step guide, if you need some documentation and help
这篇关于如何将文件和文件夹添加到GitHub仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!