在ubuntu上搭建git-server及android studio使用git

 一、在 Server 端安装 gitosis(在 Server 端进行)
 首先安装 git
  sudo apt-get install git-core
 然后安装 python 工具,因为后面安装 gitosis 要用到 python
  sudo apt-get install python-setuptools
 接着建个文件夹,用来存放 gitosis 安装文件
  mkdir ~/src
 然后
  cd ~/src
 然后把 gitosis 项目 clone 到本机
 clone 完成后
  cd gitosis/
 然后执行安装命令
  sudo python setup.py install
 接着新增一个用户,用于操作 git 项目
  sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git
 
 二、生成 Client 端的公钥文件(在 Client 端进行的)
 然后在 Client 端,用 ssh-keygen 生成公钥
 在 Linux Clinet 上,如果还没安装 ssh,则先安装它
  sudo apt-get install openssh-client
 然后执行生成公钥的命令
  ssh-keygen
 (注:在 windows 上,可通过安装 cygwin 及其相关插件来获得 openssh-client,然后在 cygwin 终端里执行 ssh-keygen,就可以生成公钥了)

三、把 Client 端的公钥文件添加到 gitosis 上,假设文件名为 id_rsa.pub(在 Server 端进行的)
 在 Client 端生成公钥文件后,把它拷贝到 Server 上,假设我已经把它拷贝到 Server 的 /home/lion/work-dir/client-info/ 目录下
 然后,进入刚才我们安装 gitosis 的目录,执行
  sudo -H -u git gitosis-init < /home/lion/work-dir/client-info/id_rsa.pub 
 这个命令的作用是把 Client 的公钥加入到 gitosis 上,这样 Client 就可以连接到 Server 上的 gitosis 了
 最后修改一个 Server 上一个文件的权限
  sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update

四、在 Client 端进行测试
经过上面的步骤,我们已经在 Server 端安装配置好了 git 服务,而且已经把 Client 端的公钥文件加入到 Server 的 gitosis 上了。下面我们就可以在 Client 端访问 Server 上的 git 服务了。
我们在 Client 端创建一个测试目录
 mkdir git-test
 cd git-test
 git init
 然后执行 clone 命令,把 Server 上的项目 clone 到 Client 上(假设 Server 的 ip 是 192.168.0.144)
 git clone git@192.168.0.144:gitosis-admin.git

 然后就可以看到下面的信息,一切成功



五、在 Android studio 上使用 git

Android Studio has git plugin, which can make you have a well version control on your project.

In this part, I will show you how to create a new repository at Android Studio on Windows OS.


Prepare :

At the first, you should install Git for Windows.

And then, Setting git tools path for Android Studio.

File > Settings > Version Control > Git

You can click Test button to check function. Such as figure below.



Step 1 : Enable Version Control Integration(git init)

VCS > Enable Version Control Integration > select "Git"

And then, you will discovery that your project list changed color. Like figure.


※ build folder & local.properties doesn't added.


Step 2 : Git Add Remote

In this step, Android Studio doesn't provide GUI to work, We should use Git for Windows tool.

Go find Git Bash in git folder.

  1. Git Bash > Go to Project folder

  2. Git Bash > key in add remote command
    Ex: git remote add origin git@192.168.0.1:user/android-studio-git.git





Step 3 : Add to VCS(git add)

Select <project/file> > VCS > Git > Add to VCS




Step 4 : Commit Changes(git commit)

VCS > Commit Changes...

Write down commit message, then choose commit.

If you select Commit and Push..., the git push window will pop up.



Step 5 : Git Push(git commit)

VCS > Git > Push

If your repository is empty, you must select Push current branch to alternative branch


If push completely, you will see Push Secessfully at the bottom of Android Studio.

This tutorial's git server is private server, not GitHub.

Pushing to GitHub is easier, I will write down later.

Now, enjoy version control at Android Studio with Git.


PS.

I perfer to install tortoise git, addtionally.

Because icons, open on windows, would be more pretty.

Moreover, you can use GUI to do Step 2.


注意:在有些机子上,Android studio 中使用 Git 有些问题,可能会报下面这种错误
git.exe: error while loading shared libraries: ?: cannot open shared object
但是,无论操作是否成功,studio 都会在控制台(console)中打出它要执行的 git 命令,我们可以把这个命令 copy 下来,用自己的操作终端(如 cygwin)来执行这个命令就行了。


如果你对 Gitosis 不熟的话,可以来看一下这篇文档



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Storm-Shadow

你的鼓励将是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值