提示:以下是本篇文章正文内容,下面案例可供参考
一、日常常用命令
查看命令
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