将新的本地目录添加到 git 远程分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4917472/
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 05:00:55  来源:igfitidea点击:

Add new local directory to a git remote branch

git

提问by Patrick Dattilio

I have a directory on my PC I'd like to add to a particular branch in a remote git repo on my server. I have git, the branch was created fresh off the master from the server, but I've got an entire project with which I would like to use git.

我的 PC 上有一个目录,我想将其添加到服务器上远程 git 存储库中的特定分支。我有 git,这个分支是从服务器的 master 上创建的,但我有一个完整的项目,我想使用 git。

What is the best way to go about this?

解决这个问题的最佳方法是什么?

回答by John Douthat

Clone the remote repository on to your PC.

将远程存储库克隆到您的 PC 上。

git clone [email protected]:myproject.git

git clone [email protected]:myproject.git

Checkout the branch to which you would like to add those files.

签出要添加这些文件的分支。

cd myproject

cd myproject

git checkout -b my_new_branch

git checkout -b my_new_branch

Move the files into your project directory, then add & commit them.

将文件移动到您的项目目录中,然后添加并提交它们。

git add .

git add .

git commit -m "new files for my new branch"

git commit -m "new files for my new branch"

You'll probably want to push, too.

你可能也想推动。

git push origin my_new_branch

git push origin my_new_branch