首先在本地创建ssh key;
1
|
$ssh-keygen-t rsa -C "your_email@youremail.com"
|
后面的your_email@youremail.com改为你的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。为了验证是否成功,在git bash下输入:
1
|
$ssh-T git@github.com
|
如果是第一次的会提示是否continue,输入yes就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们。
1
2
|
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
|
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/username/mygitrep.git
git push -u origin master
Push an existing repository from the command line
git remote add origin https://github.com/username/mygitrep.git
git push -u origin master