ubuntu用git/repo拉取gerrit代码前的本地基础配置

本文介绍了在Ubuntu系统中配置Git和Repo以连接并使用Gerrit代码审查系统的详细步骤,包括创建SSH密钥、添加到Gerrit服务器、编辑.ssh/config文件、配置Git、验证SSH设置、安装Repo、验证Repo以及请求权限和同步代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Create you SSH-key.

If you've already generated it, you don't need to regenerate it !
else:
$ssh-keygen  -t  rsa  -C  your-email
Now the public key will be located in ~/.ssh/id_rsa.pub


2. Add your key to Gerrit server.

$cat  ~/.ssh/id_rsa.pub
• Open web of gerrit , sign in
• Click “Settings” and then “SSH Public keys”. Paste the entire contents of your ~/.ssh/id_rsa.pub into the textbox and click the “add” button.


3. Create or edit the file ~/.ssh/config and add configuration.

$sudo apt-get install vim    (you need know a little VIM, if not, please use gedit)
$vi  ~/.ssh/config   or   gedit ~/.ssh/config
Paste and edit the following content:

Host gerrit1
    HostName XXXXX
    Port 29418
    User your-gerrit-login-username
    IdentityFile ~/.ssh/id_rsa

$chmod og-rwx  ~/.ssh/config


4. Config Git

$sudo apt-get install git
$git config --global user.email “your-gerrit-email”
$git config --global user.name “your-gerrit-login-username”
$vi ~/.gitconfig

Paste and edit the following content:

[review "http://XXXXX:8080"]
        username = your-gerrit-login-username

 

5. Now to verify your ssh setup is okay and key is working correctly, try to connect to Gerrit’s SSH port:

$ssh gerrit1
If the following information appears, the configuration is successful:
 ****    Welcome to Gerrit Code Review    ****

 

6.  Install repo

$mkdir ~/bin

get the repo from your team, and copy repo to ~/bin/

$vi ~/bin/repo

edit the REPO_URL  and  REPO_REV for your repo
for example

REPO_URL = 'ssh://XXXX/repo'
REPO_REV = 'stable'

$chmod +x ~/bin/repo
$ sudo vi ~/.bashrc

Add a new line at the end:

export PATH=$PATH:~/bin

$source ~/.bashrc

PS:

If you want to get the repo for yourself:

$git clone https://code.youkuaiyun.com/kangear/git-repo.git -b stable

$cp git-repo/repo ~/bin

 


7.  Verify repo

$repo help
If the following information appears, the configuration is successful:
 cmd :  help
 usage: repo COMMAND [ARGS]
 repo is not yet installed.  Use "repo init" to install it here.
 The most commonly used repo commands are:
  init      Install repo in the current working directory
  help      Display detailed help on a command
 For access to the full online help, install repo ("repo init").


8.   Then, you can request the access permission and try to sync the code.

You can use 'git clone XXX' or 'repo init -u XX -m XX -b XX' to sync code.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值