deepin(debian)下使用Git

时间:2023-03-09 02:52:38
deepin(debian)下使用Git

Github

github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开。

安装git

  • 安装
sudo apt-get install git
  • 配置用户名和邮箱
git config --global user.name "用户名"

git config --global user.email "邮箱"
  • 生成ssh公钥、私钥
ssh-keygen -t rsa

三次回车

  • 查看公钥

    进入.ssh
cd ~/.ssh

打开公钥文件

gedit id_rsa.pub
  • 复制公钥到github(或者码云、gitliab)

以github为例

  • 创建github账号并登入账号

网站地址:https://github.com

  • 进入 Account Settings(账户配置),左边选择SSH Keys,Add SSH Key,title随便填,粘贴在你电脑上生成的key。

    deepin(debian)下使用Git
  • 为了验证是否成功,在git bash下输入:
$ ssh -T git@github.com

如果是第一次的会提示是否continue,输入yes就会看到:You've successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。

  • 把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们。
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"

进入要上传的仓库,右键git bash,添加远程地址:

$ git remote add origin git@github.com:yourName/yourRepo.git

面的yourName和yourRepo表示你再github的用户名和刚才新建的仓库,加完之后进入.git,打开config,这里会多出一个remote "origin"内容,这就是刚才添加的远程地址,也可以直接修改config来配置远程地址。

创建新文件夹,打开,然后执行 git init 以创建新的 git 仓库。

  • 检出仓库

    执行如下命令以创建一个本地仓库的克隆版本:
git clone /path/to/repository

如果是远端服务器上的仓库,命令会是这个样子:

git clone username@host:/path/to/repository