git 本地仓库推送到远程仓库以及常用命令

版权声明:转载请注明博主地址 https://blog.csdn.net/weixin_43885417/article/details/84932863
  1. 现在本地初始化一个git仓库,名字自己定,在文件夹里右键,选择‘Git Bash Here
 git init
  1. 然后,关联远程仓库
 git remote add origin  + 你的远程git仓库地址。
  1. 下一步,就可以把本地库的所有内容推送到远程库上(把本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程。)
 git push -u origin master 
  1. 第一次连接github,会有一个警告:
The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?

这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes回车即可。
Git会输出一个警告,告诉你已经把GitHub的Key添加到本机的一个信任列表里了。

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

以后再操作远程仓库,就不会再有警告了,如果你想克隆远程仓库东西,可以直接执行:

git clone + ‘项目的远程仓库地址’

git的其他常用命令:

git init                           //初始化本地git环境
git clone XXX                      //克隆一份代码到本地仓库
git pull                           //把远程库的代码更新到工作台
git pull --rebase origin master    //强制把远程库的代码跟新到当前分支上面
git fetch                          //把远程库的代码更新到本地库
git add .                          //把本地的修改加到stage中
git commit -m 'comments here'      //把stage中的修改提交到本地库
git push 			   //把本地库的修改提交到远程库中
git branch -r/-a	           //查看远程分支/全部分支
git checkout master/branch         //切换到某个分支
git checkout -b test               //新建test分支
git checkout -d test               //删除test分支
git merge master                   //假设当前在test分支上面,把master分支上的修改同步到test分支上
git merge tool                     //调用merge工具
git stash                          //把未完成的修改缓存到栈容器中
git stash list                     //查看所有的缓存
git stash pop                      //恢复本地分支到缓存状态
git blame someFile                 //查看某个文件的每一行的修改记录()谁在什么时候修改的)
git status                         //查看当前分支有哪些修改
git log                            //查看当前分支上面的日志信息
git diff                           //查看当前没有add的内容
git diff --cache                   //查看已经add但是没有commit的内容
git diff HEAD                      //上面两个内容的合并
git reset --hard HEAD              //撤销本地修改
echo $HOME                         //查看git config的HOME路径
export $HOME=/c/gitconfig          //配置git config的HOME路径

如何你是团体协作的话,学会下面的命令:

git clone XXX         //克隆代码库
git checkout -b test  //新建分支
modify some files     //完成修改
git add .             //把修改加入stage中
git commit -m ''      //提交修改到test分支
review代码
git checkout master   //切换到master分支
git pull              //更新代码
git checkout test     //切换到test分支
git meger master      //把master分支的代码merge到test分支
git push origin 分支名 //把test分支的代码push到远程库

git 执行流程图:
FFFF,t_70)

猜你喜欢

转载自blog.csdn.net/weixin_43885417/article/details/84932863