在树莓派上3b的操作,可以利用ssh进行登陆操作:
添加一个”Git”用户和组
增加git用户和组
adduser --system --shell /bin/bash --gecos ‘git version control by pi‘ --group --home /home/git git
注意:/home/git是这个例子里我使用的文件夹。如果你想使用别的路径,替换下面命令里的”/home/git”。
修改Git 用户密码
passwd git
切换到git用户
su git
增加一个空的Git仓库(Git Repository)
切换到GIT跟目录下
cd /home/git
建立仓库并初始化
mkdir test.git
cd test.git
git --bare init
在本地PC上的操作:
Push你的代码到Pi上
加入一个新的远程主机(假设树莓派IP为192.168.0.22,根据自己主机更改自IP),origin代表你本地需要上传的git文件
git remote add origin [email protected] :/home/git/test.git
add增加你的代码,commit提交到本地,然后push到远程。
git add .
git commit -am "Initial"
git push origin master
在push过程中需要你提供上述git用户的密码,因此刚才设置的密码需要记住。类似这样的消息”authenticity of host …”只需要输入”yes”然后继续就可以了。
如果一切正常,你的Git仓库已经搭建在你的树莓派上了。
测试clone代码到Windows机器上,更改路径到一个空文件夹,然后通过命令行(或git bash),运行:
git clone [email protected]:/home/git/test.git
另外,git的使用见git使用教程:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
原文:http://www.cnblogs.com/-jimmy-/p/6980287.html