前言
我有一种需求,在我的树莓派上运行一个git远程仓库,并且还能看到仓库中的文件。
上网搜集了一些资料,就有了这个教程。
安装 git
这很简单,直接用包管理器装就好了,这里就不再赘述了。
创建远程仓库
为了方便管理,我先在树莓派上创建了一个叫 git
的新用户:
|
|
然后用 git
用户在家目录下创建一个远程的仓库(不是裸仓库)
|
|
创建本地仓库
如果有现成的仓库,继续用就行了,如果没有,就新建一个:
|
|
然后在这个仓库里加入你想加入的各种文件或目录。
我的仓库里现在有了以下内容:
|
|
先把它们提交一下:
|
|
关联远程仓库
关联远程仓库很容易:
|
|
然后push一下看看?
~/local_repo $ git push --set-upstream origin master
git@192.168.0.200's password:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 203 bytes | 203.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 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: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To 192.168.0.200:remote_repo
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '192.168.0.200:remote_repo'
很遗憾提交被拒绝了!下面继续操作。
配置接受提交
根据报错,在远程仓库目录下执行以下命令就能接受提交了:
|
|
再push一下
~/local_repo $ git push --set-upstream origin master
git@192.168.0.200's password:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 203 bytes | 203.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To 192.168.0.200:remote_repo
* [new branch] master -> master
branch 'master' set up to track 'origin/master'.
提交成功了!
让文件可见
做完之前的工作之后,当你查看远程仓库的目录时,你发现什么也没有:
|
|
下面才是重点。
当你查看 .git
目录时,你会看到这些文件:
|
|
我们需要的是 post-update.sample
,把它改名为 post-update
:
|
|
然后编辑 post-update
文件,更换为以下内容:
|
|
在本地仓库提交些更改后push一下:
|
|
看下远程仓库的目录:
|
|
文件都出现了!
愉快地使用 git
接下来的各种玩法就看你自己了!