git仓库远程连接GitHub

1 先下载git for windows

然后一直点下一步安装.

2 安装之后,选择git gui.生成ssh 链接 git 公钥.

用命令也可以:

$ ssh-keygen -t rsa -C "your_emali@youemal.com"

然后输入密码.

建议用第一种方式。第二种网上说是可以,但是我没成功过。

然后输入密码。

3 将公钥添加到开源中国上,或者是github中

在开源中国中新建一个公钥,然后将.ssh文件夹下的id_ras_pub中的内容复制到文本框中,这里的title可以随意.

4 测试链接:

输入命令:$ ssh -T git@git.oschina.net

然后输入yes

如果成功可以看到你的用户名和邮箱.

出现错误可以测试:$ ssh -Tv git@git.oschina.net

5 设置用户名和邮箱

$ git  config user.name"you name"

$git  config user.email"you_email@youemal.com"

6 然后在web开源中国中创建一个project.

7 测试上传文件

 创建文件夹,需要和你建立的projexct同名。

mkdir hello

cd hello

git init

touch README

git add README

git commit  -m  'frist commit' 

8 提交

git remote add test git@git.oschina.net:web用户名/hell.git

git push -u test master

如里有报错误:

To git@git.oschina.net:yangzhi/hello.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@git.oschina.net:yangzhi/hello.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first merge the remote changes (e.g.
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

可以输入:

git push -f 

可以ok了.

10 克隆代码

git clone git@github..com:用户名/项目名.git

`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````

一.删除已有仓库

如果我们想要删除Github中没有用的仓库,应该如何去做呢?

进入到我们需要删除的仓库里面,找到“settings”即仓库设置:

然后,在仓库设置里拉到最底部,找到“Danger Zone”即危险区域:

点击“Delete this repository”这样就可以删除该仓库了。

二.删除Github中的某个文件或文件夹

我们知道,在Github上我们只能删除仓库,并不能删除文件或者文件夹,所以只能用命令来解决。

1.本地仓库和远程仓库同时删除

例如要删除如图所示的_config.yml和index.md两个文件:

我们先在本地把两个文件删除,然后执行以下命令:

$ git add * //把本地仓库的文件上传到缓存。
$ git commit -m 'del' //把第一步上传到缓存的东西上传到本地仓库,其中'del'是操作标识,内容随便填,方便用户观看。
$ git push origin master //把本地仓库的文件上传到远程仓库。


这样,再打开远程仓库就可以看到两个文件已经被删除了:

2.只删除远程仓库,不删除本地仓库

假如我们现在仓库里有一张git-process.png的图片,我们想要在远程仓库把它删除,但在本地并不想把它删除:

在命令窗口输入以下命令:

$ git pull origin master //将远程仓库里面的项目拉下来。
$ dir

原文地址:https://www.cnblogs.com/tulintao/p/10884203.html