Git远程连接GitHub
在B站上学习上了一下Git和GitHub的教程(视频地址:https://www.bilibili.com/video/av10475153/),简单的整理了一下流程和期间遇到的一些问题。
一、安装Git
下载地址:https://git-scm.com/downloads。Windows平台下默认安装即可。可参考百度经验:https://jingyan.baidu.com/article/9f7e7ec0b17cac6f2815548d.html
二、注册Github账号
三、远程连接
(1)、基本信息设置
设置用户名
git config --global user.name '自己的用户名'
设置用户名邮箱
git config --global user.email '自己的邮箱'
运行完可以在C:\Users\用户名 下.gitconfig查看内容
(2)、初始化一个新的Git仓库
1、创建文件夹
右键新建/mkdir test
2、在新建文件夹内初始化git(创建git仓库)
cd test//进入test文件夹
git init
(3)、向仓库添加文件
1、创建文件
touch 1.cpp
git status//查看状态
2、添加到暂存区
git add 1.cpp
3、将文件从暂存区提交到仓库
git commit -m 'add 1.cpp'
(4)*、修改仓库文件
1、修改1.cpp 内容
cat 1.cpp //可以查看内容
2、添加到暂存区
git add 1.cpp
3、将文件从暂存区提交到仓库
git commit -m 'change 1.cpp'
(5)*、删除仓库文件
1、删除文件
rm -rf 1.cpp
2、从Git中删除文件
git rm 1.cpp
3、提交操作
git commit -m '删除 1.cpp'
注:带*不是必须操作,供以后操作参考
(6)GitHub上创建仓库
(7)添加ssh秘钥
输入:ssh-****** -t rsa -C "[email protected]"
输入:clip < ~/.ssh/id_rsa.pub 复制秘钥 注:目录为C:\Users\用户名
添加秘钥到GitHub:
左边选择 SSH and GPG keys,然后点击 New SSH key 按钮,title 设置标题,可以随便填,粘贴在你电脑上生成的 key。
(8)要关联一个远程库,使用命令git remote add origin [email protected]:path/repo-name.git;
[email protected]:path/repo-name.git 替换为自己的,在这里复制
关联后,使用命令git push -u origin master第一次推送master分支的所有内容;
此后,每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;
问题:
1、 $ git push -u origin master
ssh: Could not resolve hostname server-name: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
查看.git文件夹下 config文件
[core]repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = [email protected]:path/repo-name.git
fetch = +refs/heads/*:refs/remotes/origin/*
发现url = [email protected]:path/repo-name.git错误,改为自己的地址,参考步骤(8)
参考文档:
1、https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013752340242354807e192f02a44359908df8a5643103a000
2、http://www.runoob.com/git/git-remote-repo.html
3、http://blog.csdn.net/yemoweiliang/article/details/53005156
4、http://blog.csdn.net/hwb1992/article/details/23055943