git 将文件上传到 github 中的一个分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40643488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:26:03  来源:igfitidea点击:

upload files to a branch in github

gitgithub

提问by rowana

I know there are hundreds of tutorials out there on this, but I couldn't figure where to start. I am using a MAC and am on a remote system which runs Ubuntu 14.04. What I want to do is upload folders to my organization's github repository. There already exists a repo, and I want to create a branch and upload my files and folders in that branch.

我知道有数百个关于此的教程,但我不知道从哪里开始。我正在使用 MAC 并且在运行 Ubuntu 14.04 的远程系统上。我想要做的是将文件夹上传到我组织的 github 存储库。已经存在一个 repo,我想创建一个分支并在该分支中上传我的文件和文件夹。

I tried doing

我试着做

git branch branch_name
git checkout branch_name

However the branch does not show up on the webpage. I also tried creating a branch from the webpage, but I dont know how to upload files to it. I am also not sure how to actually navigate to the repository to which I want to upload.

但是,该分支并未显示在网页上。我也尝试从网页创建一个分支,但我不知道如何将文件上传到它。我也不确定如何实际导航到我要上传的存储库。

Please give me instructions as to how I could go about doing this.

请告诉我如何去做这件事。

Thank you!

谢谢!

回答by OldBunny2800

  1. Find your repository. (Pick the folder you think it's in, and run ls -a. If you see .git, you're probably in the right place.
    • If you do not have the repository initilized yet, do one of the following:
      • If you have all the files copied from the repository, all you need to do is git init.
      • If you have nothing, run git clone <https://something/foo/bar.git> <folder you want the repository to be in>. If you specify nothing for the folder, it will create it in the current folder.
  2. Create a branch: You can use a single command instead of the two commands you have in your question: git checkout -b <your branch name>
  3. Make some changes in the files.
  4. Track your changes: git add <changed file> [<another changed file> [...]]Note that a changed file can be a folder.
    • If you deleted a file, use git rm <file>so Git knows you deleted it.
  5. Commit your changes: git commit -m "what you did"
  6. If you need to push your changes back to the main branch, use git checkout masterand git merge <your branch name>. This will move all commits on your new branch to the original branch.
  7. Push your changes to the online repository: git push
    • For your first time pushing any branch, use this instead: git push --set-upstream <https://something/foo/bar.git> <your branch name>
    • From now on, you can incorporate changes from the online branch to your local by using git pull.
    • If changes are made on master that should be in your branch, checkout your branch and use git rebase master.
  1. 找到您的存储库。(选择您认为它所在的文件夹,然后运行ls -a。如果您看到.git,您可能在正确的位置。
    • 如果您尚未初始化存储库,请执行以下操作之一:
      • 如果您已从存储库复制了所有文件,则您需要做的就是git init.
      • 如果你什么都没有,就跑git clone <https://something/foo/bar.git> <folder you want the repository to be in>。如果您没有为文件夹指定任何内容,它将在当前文件夹中创建它。
  2. 创建分支:您可以使用单个命令而不是问题中的两个命令: git checkout -b <your branch name>
  3. 对文件进行一些更改。
  4. 跟踪您的更改:git add <changed file> [<another changed file> [...]]请注意,更改的文件可以是文件夹。
    • 如果您删除了一个文件,请使用,git rm <file>以便 Git 知道您删除了它。
  5. 提交您的更改: git commit -m "what you did"
  6. 如果您需要将更改推送回主分支,请使用git checkout mastergit merge <your branch name>。这会将新分支上的所有提交移动到原始分支。
  7. 将您的更改推送到在线存储库: git push
    • 第一次推送任何分支时,请改用它: git push --set-upstream <https://something/foo/bar.git> <your branch name>
    • 从现在开始,您可以使用git pull.
    • 如果对应该在您的分支中的 master 进行了更改,请检查您的分支并使用git rebase master.

Sorry if I went into too much detail!

对不起,如果我说得太详细了!

回答by KeyWeeUsr

  1. Create a branch with git checkout -b <branch>
  2. Do stuff & commit
  3. git push --set-upstream <remote> <my_branch>e.g. origin <branch>
  1. 创建一个分支 git checkout -b <branch>
  2. 做事并提交
  3. git push --set-upstream <remote> <my_branch>例如 origin <branch>

All of that if you have a remote set. If not, set a remote first.

如果你有一个遥控器,所有这些。如果没有,请先设置遥控器。

回答by KeyWeeUsr

You need to push your branch to your remote repository. Notice that the -uoption sets the upstream for your local branch, so that every following push refers to the given remote branch.

您需要将分支推送到远程存储库。请注意,该-u选项为您的本地分支设置上游,以便每个后续推送都引用给定的远程分支。

git push -u origin branch_name

If you don't have any configured remote repositories yet, you can do so by copying the URL of your repository and add it as a remote repository.

如果您还没有任何配置的远程存储库,您可以通过复制存储库的 URL 并将其添加为远程存储库来实现。

git remote add origin [email protected]:/YOU/REPO.git

回答by ijal

  1. creating a branch from the webpage
  2. git branch branch_name git checkout branch_name
  3. git push origin branch_name
  1. 从网页创建一个分支
  2. git branch branch_name git checkout branch_name
  3. git push origin branch_name