这个问题在这里已经有了答案:
How do I clone into a non-empty directory?
(17 个回答)
3年前关闭。
我有一个包含文件夹和文件的 git 存储库。并在本地拥有与 git 相同的文件夹,但文件略有更改但未连接到 git。
如何将我的本地文件夹连接到同一个 git 并提交我所做的所有更改?
最佳答案
如果您的本地文件夹不是 git 存储库,您应该首先将其设为存储库并在新分支中提交您的更改,然后添加一个远程链接到您要推送包含更改的分支的现有存储库。
$ cd path/to/your/local/directory
$ git init # make it a git repository
$ git checkout -b my_awesome_branch # checkout to a new branch containing your local changes
$ git add --all
$ git commit -m 'This should be a Message describing your local changes'
您将在 git branch
my_awesome_branch
中拥有所有本地更改.现在,您需要设置一个上游到远程存储库,您将在其中推送此 my_awesome_branch
.$ git remote add my_awesome_upstream <your-upstream-git-repository-url>
$ git remote -v # To list remotes, and see if your remote is added correctly
$ git push my_awesome_upstream my_awesome_branch
现在,您可以转到远程存储库并 checkout 到
my_awesome_branch
从 UI 以查看您的更改。要将更改 merge 到主分支(例如,通常是
master
),您可以针对主分支打开 merge/pull 请求,并在将更改 merge 到主分支之前检查您的更改。希望能帮助到你。
如果上述任何一项不清楚,请告诉我。我会联系你。
资源:
关于git - 我如何在现有文件夹中git init,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51123925/