Git命令操作

安装配置
	将其bin目录添加到path
	ssh -keygen -t rsa -C 自己的邮箱(获取ssh远程连接秘钥)
使用:
	进入项目目录 右击进入git bash 执行git init
	github上new一个新仓库复制生成的例如:git@github.com:qinyios/mygitproject.git
	然后执行git remote add origin git@github.com:qinyios/mygitproject.git 和远程仓库建立项目的联系

命令
	
	git add 本地文件提交到暂存区
	git commit 暂存区提交到本地仓库
	git push将本地仓库的内容推送到远程仓库
	git pull将远程仓库的内容拉取到本地仓库

第一次发布项目
	ssh-keygen -t rsa
	git add .
	git commit -m “注释内容”
	git remote add origin git@github.com:qinyios/mygitproject.git
	git push -u origin master

	git clone

	第二次提交:git push  origin master

如果报错:To github.com:qinyios/mygitproject.git
	 ! [rejected]        master -> master (fetch first)
	error: failed to push some refs to 'git@github.com:qinyios/mygitproject.git'
	hint: Updates were rejected because the remote contains work that you do
	hint: not have locally. This is usually caused by another repository pushing
	hint: to the same ref. You may want to first integrate the remote changes
	hint: (e.g., 'git pull ...') before pushing again.
	hint: See the 'Note about fast-forwards' in 'git push --help' for details.
	解决办法:
		git pull --rebase origin master 再git push origin master



git add 			将文件添加进暂存区
git commit 			将文件提交到本地分支
git checkout +		分支名字 切换分支
git checkout -b dev 创建并切换分支到dev
git branch 			命令会列出所有分支,当前分支前面会标一个*号
git merge dev 		把dev分支的工作成果合并到master分支上
git branch -d dev	删除dev分支//强制删除方法git branch -D dev;强制删除原因是远程分支删除了,本地还没删除所以要强制删除
git log --graph		命令可以看到分支合并图
git checkout --filename 		把文件从工作区中修改的部分撤销
git reset HEAD readme.txt 		可以把暂存区的修改撤销掉,重新放回工作区
git status 						查看状态
git rm test.txt + git commit -m "remove test.txt" 	删除文件并提交
git push origin +分支名字	把本地库的所有内容推送到远程库上

git stash 把当前工作现场“储藏”起来,等以后恢复现场后继续工作
git stash pop恢复的同时把stash内容也删了
git stash apply恢复,但是恢复后,stash内容并不删除,你需要用git stash drop来删除

git remote -v 查看远程库的信息
git clone 从远程库clone
git branch --set-upstream branch-name origin/branch-name建立本地分支和远程分支的关联

  

原文地址:https://www.cnblogs.com/qinyios/p/11124514.html