Linux命令行下使用GitHub

1.注册github账号

2.创建ssh密钥

cd ~

ssh-keygen -t rsa -C your_email@example.com

1

2

cd~

ssh-keygen-trsa-Cyour_email@example.com

545abbc2eadf0b21cc54326c255bdd92.gif

会在~/.ssh/下生成id_rsa.pub文件,在github网站上的SSH and GPG keys —>New SSH Keys,标题随便写,可以写计算机的名字,将id_rsa.pub里面的内容粘贴key里,最后点击Add SSH Key。

3.打开终端

ssh -T git@github.com

1

ssh-Tgit@github.com

这一步如果提示Permission denied (publickey),就执行ssh-keygen -t rsa -b 4096 -C "your_email@example.com"重新产生key,出现一下提示,说明以正常连接到github

Hi ganchunsheng! You've successfully authenticated, but GitHub does not provide shell access.

1

Higanchunsheng!You'vesuccessfullyauthenticated,butGitHubdoesnotprovideshellaccess.

545abbc2eadf0b21cc54326c255bdd92.gif

4.在github上创建仓库

上传代码按照这个步骤:

git init #初始化

git add . #初始化本地仓库

git commit -m "first commit" #加注释,并提交到本地仓库

git remote add origin https://github.com/xxxx/test.git #连接远程仓库

git push -u origin master #将本地仓库的东西提交到master分支下

1

2

3

4

5

gitinit#初始化

gitadd.#初始化本地仓库

gitcommit-m"first commit"#加注释,并提交到本地仓库

gitremoteaddoriginhttps://github.com/xxxx/test.git #连接远程仓库

gitpush-uoriginmaster#将本地仓库的东西提交到master分支下

545abbc2eadf0b21cc54326c255bdd92.gif

5.下载代码

master分支:

git clone https://github.com/xxxx/test.git #xxxx为用户名

1

gitclonehttps://github.com/xxxx/test.git #xxxx为用户名

545abbc2eadf0b21cc54326c255bdd92.gif

包含子分支:

git clone --recursive https://github.com/xxxx/test.git

1

gitclone--recursivehttps://github.com/xxxx/test.git

6.常见问题

(1)提示错误:fatal: remote origin already exists.解决办法:

git remote rm origin

1

gitremotermorigin

(2)git未初始化

***Please tell me who you are.

Run

git config --global user.email "you@example.com"

git config --global user.name "Your Name"

1

2

3

4

***Pleasetellmewhoyouare.

Run

gitconfig--globaluser.email"you@example.com"

gitconfig--globaluser.name"Your Name"

545abbc2eadf0b21cc54326c255bdd92.gif

解决办法:

git config --global user.name "your_email"

config --global user.email your_email@example.com

1

2

gitconfig--globaluser.name"your_email"

config--globaluser.emailyour_email@example.com

Logo

更多推荐