我,因为这里到达(同样的问题)之后加入这个答案,没有答案的真正描述了所有所需的必要步骤从无到有完全可用的远程(裸)回购。
注意:本示例使用本地路径作为裸回购的位置,但其他git协议(如OP指示的SSH)应该可以正常工作。
我试着在那些不太熟悉git的路上添加一些注释。
1.初始化裸回购...
> git init --bare /path/to/bare/repo.git
Initialised empty Git repository in /path/to/bare/repo.git/
这将创建一个文件夹(repo.git),并与代表一个git仓库git的文件填充它。现在,这个回购没用 - 它没有提交,更重要的是,没有分支。虽然你可以克隆这个回购,但你不能从中获利。
接下来,我们需要创建一个工作文件夹。有几种方法可以做到这一点,这取决于你是否有现有的文件。
2a。通过克隆空回购
git clone /path/to/bare/repo.git /path/to/work
Cloning into '/path/to/work'...
warning: You appear to have cloned an empty repository.
done.
此命令,如果/path/to/work
不存在,或者是一个空文件夹只会工作,创建一个新的工作文件夹(不存在的文件)。 注意警告 - 在这个阶段,你还没有任何有用的东西。如果您cd /path/to/work
和运行git status
,你会得到这样的:
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
但是这是一个谎言。你并不是真的在分支master
(因为git branch
什么也没有返回),到目前为止,没有提交。
接下来,在工作文件夹中复制/移动/创建一些文件,将它们添加到git并创建第一次提交。如果你还没有告诉过git的你是谁,只需要
> cd /path/to/work
> echo 123 > afile.txt
> git add .
> git config --local user.name adelphus
> git config --local user.email [email protected]
> git commit -m "added afile"
[master (root-commit) 614ab02] added afile
1 file changed, 1 insertion(+)
create mode 100644 afile.txt
的git config
命令。请注意,如果您现在运行git branch
,您现在将看到master
分支列出。现在运行git status
:
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working directory clean
这也有误导之嫌 - 上游并没有“水涨船高”,它只是尚未创建,git branch --unset-upstream
也无济于事。但是,没关系,现在我们已经有了第一次提交,我们可以推送并且掌握将在裸仓库上创建。
> git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /path/to/bare/repo.git
* [new branch] master -> master
在这一点上,我们有一个全功能的裸回购其可以在其他地方上的主分支被克隆以及本地工作副本可以推拉。
> git pull
Already up-to-date.
> git push origin master
Everything up-to-date
2b。从现有文件创建一个工作文件夹 如果你已经有一个文件夹(所以你不能克隆),你可以初始化一个新的git仓库,添加第一个提交,然后将其链接到裸回购。
> cd /path/to/work_with_stuff
> git init
Initialised empty Git repository in /path/to/work_with_stuff
> git add .
# add git config stuff if needed
> git commit -m "added stuff"
[master (root-commit) 614ab02] added stuff
20 files changed, 1431 insertions(+)
create mode 100644 stuff.txt
...
在这一点上,我们有我们的第一个承诺和一个本地主分支,我们需要变成一个远程跟踪上游分支。
> git remote add origin /path/to/bare/repo.git
> git push -u origin master
Counting objects: 31, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (31/31), done.
Writing objects: 100% (31/31), 43.23 KiB | 0 bytes/s, done.
Total 31 (delta 11), reused 0 (delta 0)
To /path/to/bare/repo.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
注上GIT中推-u
标志设置(新)追踪上游分支。 和以前一样,我们现在有一个功能齐全的裸回购,它可以在主分行的其他地方克隆,也可以在本地工作副本上进行推送。
所有这些对某些人来说似乎都很明显,但git在最好的时候让我感到困惑(这是错误和状态信息确实需要一些返工) - 希望这可以帮助其他人。
如果您计划让其他人推送到此回购,您还可以为'init'添加'--shared'选项。它会自动将组写入权限添加到存储库 - [链接](http://git-scm.com/book/en/Git-on-the-Server-Getting-Git-on-a-Server) – prasanthv
我认为这些三条线有比这同样的效果只有一个: 混帐--bare初始化test_repo.git 至少我目前的Git版本(1.8.2.2) –
@Fran不利于1.7 *版本似乎:\ – deepdive