0

I have a folder on ~/Documents/Share that contains classes that I use a lot and that work together. I want to transform that folder in a git submodule and then import that on Xcode 5. My idea is to use that git on a lot of projects.

I am struggling with this for the last 3 hours. I have tried a dozen "easy" instructions on the web, none worked.

How do I do that? All I want is to create a local submodule to work on a local project.

Please do not give exoteric ectoplasmic explanations... explain me like I'm five years old (because I never used git before).

Yes, I am familiar with terminal.


when I try to do git push as suggested, I see this error:

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
4

1 回答 1

5

我不确定它是否以及如何与本地子模块一起工作,但我们对我们的 bitbucket 帐户做了类似的事情。

要将您的文件夹转换为 git 存储库,请提交所有文件并将它们推送到服务器上:

cd yourdirectory
git init (1)
git add . (2)
git commit -m "this is my commit message" (3)
git remote add origin <adress-of-your-remote-git-repository> (4)
git push (5)
  1. 将您的目录转换为本地 git 存储库。
  2. 将目录中的所有文件暂存到您的 git 暂存。
  3. 提交您的暂存文件。
  4. 将远程源添加到本地存储库。
  5. 将本地存储库推送到远程引用。

您现在拥有一个包含所有文件的远程存储库。要将其用作任何启用 git 的项目中的子模块:

cd yourprojectdirectory
git submodule add <adress-of-your-remote-git-repository> (1)
git submodule update --init --recursive (2)
  1. 将远程存储库添加为新的 git 子模块。
  2. 初始化子模块,使其包含实际内容。

现在剩下的就是在查找器中打开添加的子模块的文件夹并将该文件夹拖到您的 Xcode 项目中。

要使用在本地项目中所做的一些更改来更新您的文件,您将在项目中进行更改,然后您将执行以下操作:

cd yourprojectdirectory/yoursubmoduledirectory
git add changedfile.m
git commit -m "your commit message"
git push

当然,您必须将这些更改同步到您的其他项目:

cd yourotherprojectdirectory/yoursubmoduledirectory
git pull
于 2013-10-20T13:57:02.630 回答