如何将文件和文件夹添加到 GitHub 存储库中? [英] How do I add files and folders into GitHub repos?

查看:42
本文介绍了如何将文件和文件夹添加到 GitHub 存储库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GitHub 上创建了一个帐户 —我是新来的 —我在添加文件时遇到了问题.我添加了 readme.txt.此外,我还有 3 个其他 PHP 文件和一个包含图像的文件夹.

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.

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

How do I add the files and folder? I tried it with git pull because git push origin -u master showed me an error.

推荐答案

可以使用 git add 添加文件,例如 git add README, git add <folder>/*,甚至 git add *

You can add files using git add, example git add README, git add <folder>/*, or even git add *

然后使用git commit -m ""提交文件

最后git push -u origin master来推送文件.

当您进行修改时,运行 git status 它会为您提供修改的文件列表,使用 git add * 添加它们,或者您可以单独指定每个文件,然后git commit -m 最后,git push -u origin master

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

示例 - 假设您创建了一个自述文件,运行 git status 会给您

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

运行git add README,文件被暂存以进行提交.然后再次运行 git status,它应该给你 - 文件已经添加并准备提交.

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)

然后运行 ​​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 为仓库origin推送远程分支master.

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.

运行 git pull origin master 以确保您吸收了任何上游更改

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

如果您不想将上游更改与本地存储库合并,请运行 git fetch 以获取更改,然后运行 ​​git merge 以合并更改.git pull 只是 fetchmerge 的组合.

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.

我个人使用 gitimmersion - http://gitimmersion.com/ 来了解 git 的曲线,这是一个分步指南,如果您需要一些文档和帮助

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆