git: clone、checkout、多个 ssh key

如果我们从github上复制HTTPS clone URL,然后 git clone默认是checkout主分支,如果需要切换分支:

git clone https://github.com/emlid/linux-rt-rpi
git checkout [按 TAB 键]      //看到你所要的分支,然后输入就行
或者
git checkout -b [分支的名字]     //新建一个分支然后checkout

如果只需要clone某个分支(省时间可空间)则可以:

git clone -b branch_name https://github.com/emlid/linux-rt-rpi  //只克隆 branch_name这个分支
// 可以结合 --depth <depth>
//Create a shallow clone with a history truncated to the specified number of revisions.

如果需要多个管理多个仓库,分别使用不同的ssh-key。

新建ssh-key:

ssh-keygen -t rsa -f ~/.ssh/xxx_rsa -C "Key for another repo"

$HOME/.ssh目录下新建config文件,添加如下内容(默认使用 id_rsa和 id_rsa.pub, 这里新建一个使用xxx_rsa 和 xxx_rsa.pub的规则):

Host *.host_name.*
User xxx    //不用User只写Host也行
IdentityFile ~/.ssh/xxx_rsa

Host 和 User 可以根据使用clone的仓库的地址得到;ssh、git、https有点微小区别:

ssh://[[email protected]]host.xz[:port]/path/to/repo.git/
git://host.xz[:port]/path/to/repo.git/
http[s]://host.xz[:port]/path/to/repo.git/
ftp[s]://host.xz[:port]/path/to/repo.git/
rsync://host.xz/path/to/repo.git/

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-07-31 08:56:14

git: clone、checkout、多个 ssh key的相关文章

使用Git Bash生成新的ssh key

使用Git Bash生成新的ssh key. $ cd ~  ///保证当前路径在"~"下 $ ssh-keygen -t rsa -C "你的邮箱地址"  ///建议填写自己真实有效的邮箱地址 结果: Enter file in which to save the key (/c/Users/xxxx_000/.ssh/id_rsa):   ///不填直接回车 Enter passphrase (empty for no passphrase):   ///输入密

Git第一次新建项目添加ssh key

Git第一次新建项目添加ssh key Last login: Mon Sep  3 08:59:35 on console localhost:~ dajiang$ cd ~/.ssh -bash: cd: /Users/dajiang/.ssh: No such file or directory localhost:~ dajiang$ sudo apt-get install git Password: sudo: apt-get: command not found localhost

解决git本地多ssh key的问题

最近手上一个项目需要使用到一台服务器作为专用的部署服务器,在实施过程中遇到了一些问题,具体如下: 1. 服务器的ssh默认端口和项目git仓库的ssh端口不一致 2. 部署需要使用项目提供的ssh key,不能使用服务器本身的默认ssh key 这些问题都被顺利解决了,这里特记录一下,防止遗忘. 针对上述问题,下面主要从这三个点来记录解决方案. 如何生成ssh key 如何使用特定ssh端口从git仓库拉取项目 如何使用特定密钥文件从git仓库拉取项目 一.生成 ssh key 系统默认的ssh

Git安装及SSH Key管理之Windows篇

一.安装环境 1.本机系统:Windows 10 Pro(64位)2.Git版本:Git-2.11.0-64-bit.exe(64位) 二.Git安装 去官网下载完后一路下一步完成安装,如下图: 安装完后先在系统环境变量中看下是否配置 然后在桌面右击鼠标,选择Git bash here,然后输入下面代码: git --version #验证git是否安装成功,输出版本号就代表安装成功 如下图: 安装完成有配置一下全局的用户名和邮箱,输入如下命令: git config --global user

window下配置SSH连接GitHub、GitHub配置ssh key(转载自 http://jingyan.baidu.com/article/a65957f4e91ccf24e77f9b11.html)

此经验分两部分: 第一部分介绍:在windows下通过msysGit(Git for windows.Git Bash)配置SSH Keys连接GitHub. 第二部分介绍:在GitHub上创建仓库,在本地创建项目,然后将本地项目通过SSH提交到GitHub仓库中. 工具/原料 GitHub msysGit(git for windows.Git Bash) msysGit配置SSH访问GitHub 1 检查本机是否有ssh key设置 $ cd ~/.ssh 或cd .ssh 如果没有则提示:

window下配置SSH连接GitHub、GitHub配置ssh key(转)

转自:http://jingyan.baidu.com/article/a65957f4e91ccf24e77f9b11.html 此经验分两部分: 第一部分介绍:在windows下通过msysGit(Git for windows.Git Bash)配置SSH Keys连接GitHub. 第二部分介绍:在GitHub上创建仓库,在本地创建项目,然后将本地项目通过SSH提交到GitHub仓库中. 工具/原料 GitHub msysGit(git for windows.Git Bash) msy

centos: git clone提示Permission denied publickey 问题

问题: Initialized empty Git repository in /data1/mouxuan/fastsocket-private/.git/ Permission denied (publickey). fatal: The remote end hung up unexpectedly 解决步骤: 1.cd ~/.ssh 2.ssh-keygen -t rsa -C [email protected] 遇到 提示一路 回车 遇到有Y 输入Y 3.ssh-add id_rsa

Gitblit Git 无密码 clone pull SSH Key 生成

部分内容参考自:http://blog.csdn.net/fenglailea/article/details/39317513 1.git基础配置 配置查看 git config --lis 用户名和邮箱,如果已填写过则PASS git config --global user.name "username" git config --global user.email "[email protected]" 2.生成SSH密钥(mysshkey是别名,可以任意)

Git配置SSH Key

最近看到很多人在配置Git时,遇到很问题,网上教程千篇一律.这儿自己单独记录一份. 1.检查本机是否有ssh key设置,切换到.ssh目录 $ cd ~/.ssh 或cd .ssh 2.配置git用户名和邮箱,配置多个用户时添加 --add 参数 $ git config --global --add user.name "username" $ git config --global --add user.email "email" $ git config -