初次使用git

首次安装git需要配置用户名和邮箱,否则git会提示:please tell me who you are.

你需要运行命令来配置你的用户名和邮箱:

$ git config --global user.name "youname"  $ git config --global user.email "youemail"

使用 SSH 访问工蜂

  • 使用Git Bash生成新的ssh key

    $ cd ~/.ssh     #切换到C:\Users\用户名\.ssh  $ ssh-keygen -t rsa -C "xxx@qq.com"   #新建工作的SSH key 文件,建议填写自己真实的邮箱

    执行如下方所示,提示处可以任意输入一个文件名用来生私钥,也可以不填。

    $ ssh-keygen -t rsa -C "123456@qq.com" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/zcs/.ssh/id_rsa):   # 可不填直接回车 默认id_rsa Enter passphrase (empty for no passphrase):  # 输入密码(可以为空) Enter same passphrase again:  # 确认密码 (可以为空) Your identification has been saved in /c/Users/xxxx/.ssh/id_rsa. Your public key has been saved in /c/Users/xxxx/.ssh/id_rsa.pub. The key fingerprint is: SHA256:w+iaGekSNbTEvUI0uUjFhNZCO3EVD1ly/4W7rZCiQZc 123456@qq.com The key's randomart image is: +---[RSA 3072]----+ | .oO*+=+o        | |  =+O.o= .   .   | | oo* o .. . . .  | |  ..* .o . . o   | |   . oo E   o    | |  .  + . . . o   | |   .o o . o . .  | |  .. = o . . .   | |   .= .     .    | +----[SHA256]-----+ 

    接下来你会再 .ssh 文件夹中看到 id_rsa 和 id_rsa.pub两个文件,其中 id_rsa.pub 文件中的内容便是公钥。

  • 查看 SSH KEY,并将 KEY 添加到工蜂中

    $ cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC1IPAxNRP1LbM96G4KtE51gychRfnhcaE0D2+GyHIkPTVOcdRJiEFYSWn365t2m67x81JLWpQzyRbMOKO3Xd1dLZ1st+Gf3HjP/57gwsfCu6F9a3x3UvEIL7iYzEGTT6fGd3A1KtFvwqv1fiB7GXkDoYWP6q5mkWL908PPmn2glYi+H7Ncm/sORILUk5WEjAAy39oYh4PXX65O3tB8bYEzUHOHUpvRjEWVNSXGn4ptCjnsgKYfJl12PRkSrMab9reTRv/CYFopVrY/d5REEMpcBUmz2A3yevSJTc30LUO4ydhfRHGzxzU6Xn4quzAr2+D0j+o/yKg4dQL4RXQcpNftr95ggBwtn2PaunoZIxy3yxmLXZa0NGhJl2AuoM3l0ZYKubGU7wCKxCPSy8Fgs0EbgjCfj7V4BwGDPfW6EnQQnpUpN0A1WIrHk2BUxF+aPVMlPK+fHED2BtgGWWYzNYH9HCXYrY10yICSvpK8bCVOF9ZQ3gLIrkNKksWU6dNNnEE= 123456@qq.com

    全部复制后 打开工蜂git-个人设置-ssh密钥,点击右上角的添加ssh密钥,然后把之前复制的公钥粘贴到输入框并填写一个名称即可。

  • 使用ssh的方式 clone 项目

    复制ssh路径

    使用命令 clone 项目

    $  git clone git@git.code.tencent.com:CS-work/work.git Cloning into 'work'... Enter passphrase for key 'C:\Users\zcs\.ssh\zcs': remote: Counting objects: 3, done remote: Finding sources: 100% (3/3) remote: Total 3 (delta 0), reused 3 (delta 0) Receiving objects: 100% (3/3), done.