创建仓库
- 创建仓库
git init
- 连接远程仓库
git remote add origin [远程仓库地址]
- 查看远程连接
git remote -v
- 取消与远程仓库的连接
git remote remove origin
- 推送远程仓库
git push [远程仓库地址]
- 拉取远程仓库
git pull [远程仓库地址]
更新仓库
- 添加文件
git add [文件名] 或 git add .
- 提交修改
git commit -m "日志信息"
仓库分支
- 查看本地分支
git branch
- 查看远程分支
git branch -r
- 查看远程分支
git branch -r
- 创建本地分支
git branch [name]
- 切换分支
git checkout [name]
- 创建新分支并立即切换到新分支
git checkout -b [name]
- 删除分支
git branch -D [name]
- 合并分支(将名称为[name]的分支与当前分支合并)
git merge [name]
- 创建远程分支
git push origin [name]
- 删除远程分支
git push origin :heads/[name] 或 gitpush origin :[name]
bug
- 解决git@github.com: Permission denied (publickey). Could not read from remote repository.
在命令行输入 ssh-keygen,然后当需要 选择路径、输入秘钥名字和密码时,直接输入回车即可
接下来在 github 中,在头像下选择 Settings
进入到上图界面,然后在命令行中输入 cat [刚刚保存的 id_rsa.pub 的路径],然后将内容复制到上图 Key 中即可。
- git push 时报错
错误原因:ssh 公钥出问题了,需要重新生成。