github的使用

时间:2023-03-08 18:05:39
github的使用

1.gitbub概念

github是一个基于git的代码托管平台,付费用户可以建私人仓库,免费用户用公共仓库,但是代码公开。

2.注册账户以及创建仓库

在github官网地址:https://github.com/ 注册自己的账户。 之后就可以创建仓库。

3.配置Git

启动Git Bash命令行,输入命令。

1>首先在本地创建ssh key:  ssh-keygen -t rsa -C "your_email@youremail.com";

一路回车就行,在生成的~/user/username/.ssh/id_rsa.pub里,复制里面的key。登陆GitHub,在“SSH Keys”页面:点“Add SSH Key”,填上任意Title,在Key文本框        里粘贴id_rsa.pub文件的内容:

2>验证是否成功:ssh -T git@github.com

如果是第一次的会提示是否continue,输入yes看到:You've successfully authenticated, but GitHub does not provide shell access。就表示已成功连上github。

3>设置username和email:

$ git config --global user.name "your name"

$ git config --global user.email "your_email@youremail.com"

4> 本地仓库与远端仓库连接:

git remote add origin git@github.com:yourName/yourRepo.git

进入.git,打开config,这里会多出一个remote "origin"内容,这就是刚才添加的远程地址,也可以直接修改config来配置远程地址。

如果出现有错误:fatal: remote origin already exists.

解决办法如下:

a. 先输入$ git remote rm origin

b. 再输入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!

c. 如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的    内容

d. 找到你的github的安装路径,我的是    C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

e. 找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

如果出现错误:Not a git repository (or any of the parent directories): .git

解决办法如下:输入$ git init

5> git clone

$ git clone git@github.com:usenames/gitskills.git