Git命令笔记


提示:以下是本篇文章正文内容,下面案例可供参考

一、日常常用命令

查看命令

	git config -l  //查看配置信息	
	git reflog 	//产看历史版本日志
克隆项目:git clone  git@{地址}  

分支

	git branch  					//查看分支
	git branch branch_name		//创建分支
	git checkout  branch_name		//创建且切换分支
	git checkout -b branch_name		//创建分支
	git checkout -d branch_name		//删除分支

合并分支

	git merge branch_name 	// 合并分支
	##############不可逆操作###########
	git reset --hard origin/master    //重置当前分支到远程仓库的 master 分支  

上传

初始化上传(空仓库)

	git init
	git add .
	git commit -m "内容"
	git branch -M main
	git remote add origin + 地址
	git push -u origin main

更新上传


	git add .
	git commit -m ""
	git pull
	git push
	git pull

远程仓库

	git remote -v  查看
	git remote remove origin  移除源地址
	git remote add origin 		添加源地址

二、SSH密钥

	ssh-keygen -t rsa -C "账号名/邮箱"

config文件(.ssh目录下的)

如果没config文件

新建config,命令如下:

	touch ~/.ssh/config
	vim  ~/.ssh/config	//编写文件
	esc			//回到普通模式
	i			//写入模式
	:wq 		//保存退出 
	:q 			//直接退出

config内容

	# github
	Host github.com
	HostName github.com
	PreferredAuthentications publickey
	IdentityFile ./id_rsa_github   #密钥地址

常见提示

	$ git push -u origin main
	no such identity: ./github_ssh: No such file or directory
	git@github.com: Permission denied (publickey).
	fatal: Could not read from remote repository.
问题:未找到./github_ssh
解决:.ssh/config替换绝对路径
fatal: The current branch work_pc has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin work_pc

To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
问题:线上库没有对应分支
解决:
1. 线上添加分支
2.	按照提示命令git push --set-upstream origin work_pc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值