如何在Linux上安装git?Linux上git如何配置gitee仓库?

如何在Linux上安装git?

下载(Ubuntu)

sudo apt update
sudo apt install git

验证下载

git --version

Linux上git如何配置gitee仓库?

配置

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

验证配置

git config --list	#正常则会打印出你的用户名和邮箱

生成密钥

ssh-keygen -t rsa -C "[email protected]"

如果回车后打印如下:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):

这里是在设置存储地址,直接按回车,会出现以下两种情况

  1. Enter passphrase (empty for no passphrase):
    

    按回车

    Enter same passphrase again:
    

    继续按回车,打印出密钥的随机图像则表示成功

  2. /home/username/.ssh/id_rsa already exists.
    Overwrite (y/n)?
    

    这说明已经设置了存储地址,输入“y”覆盖

    Enter same passphrase again:
    

    继续按回车,打印出密钥的随机图像则表示成功

查看公钥

cat ~/.ssh/id_rsa.pub

复制公钥到gitee

如何在Linux上安装git?Linux上git如何配置gitee仓库?_第1张图片

测试是否和gitee连通

ssh -T [email protected]

打印如下表示成功

The authenticity of host 'gitee.com (212.64.63.190)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com,212.64.63.190' (ECDSA) to the list of known hosts.
Hi username! You've successfully authenticated, but GITEE.COM does not provide shell access.

代码推送到远端仓库

  • 初始化一个仓库

    mkdir test_git/  && cd test_git/
    git init
    
  • 添加代码

    touch main.cpp
    git add .
    
  • 提交代码到仓库

    git commit -m "Add a file which names main.cpp"
    
  • 先在gitee上创建仓库:test_git

  • 添加远程仓库地址(已经被添加过了则不用执行这一步)

    git remote add origin https://gitee.com/username/test_git.git
    
  • 推送到远程仓库的master分支

    git push origin master
    

你可能感兴趣的:(Essay,git,linux)