远程连接GitHub仓库
远程连接github仓库
1,基本信息设置 ,创建秘钥
// 你的github用户名,非昵称
git config --global user.name "liuxianan"
// 填写你的github注册邮箱
git config --global user.email "xxx@qq.com"
//连续两次enter跳过 生成秘钥
ssh-keygen -t rsa -C "youremail@example.com"
2,github添加密钥
添加秘钥到GitHub:

左边选择 SSH and GPG keys,然后点击 New SSH key 按钮,title 设置标题,可以随便填,粘贴在你电脑上生成的 key。

3,检测
ssh -T git@github.com
完成上述步骤本机和github已经成功连接,后面正式开始提交代码
4,本地有一个xxx目录,选中目录,git bash
5,对本地仓库更新后更新远程仓库
git init
echo "hello " >> README.md
git add README.md
git commit -m "first commit"
//使用ssh方式
git remote add origin git@github.com:nmt/nmblog.github.io.git
git push -u origin master
之后再push之前需要先拉取远程文件到本地仓库
即
git pull origin master
git push -u origin master
6,小结
(1)将目录初始化为git本地仓库
git init
(2)添加代码文件到监控暂存区
git add . #将新文件提交到暂存区
git add README #单独添加README文件
(3)提交到本地仓库
git commit -m “first commit” #将暂存区代码提交到本地仓库,-m后为本次提交注释,"first commit"为任意即可,仅为注释
(4)添加远程仓库
git remote add origin git@github.com:nmt/nmblog.github.io.git
(5)将代码push到远程仓库
git push -u origin master
参考:http://blog.sina.com.cn/s/blog_16483ca950102yozq.html
笔记:
1-
git add . :他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。
git add -u :他仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区。add -u 不会提交新文件(untracked file)。(git add --update的缩写)
git add -A :是上面两个功能的合集(git add --all的缩写)
总结:
· git add -A 提交所有变化
· git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
· git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件
2-
git status 命令
Git 基本操作Git 基本操作
git status 命令用于查看在你上次提交之后是否有对文件进行再次修改。
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README
new file: hello.php
通常我们使用 -s 参数来获得简短的输出结果:
$ git status -s
AM README
A hello.php
AM 状态的意思是这个文件在我们将它添加到缓存之后又有改动。
3
git remote rm origin 删除当前连接的远程仓库
git push -f origin master 强制上传覆盖远程文件,
(这个命令在团队开发的时候最好不要用,否则可能会有生命危险)
如有错误,请大家指正呀😄

浙公网安备 33010602011771号