Git常见命令总结

来源:互联网 发布:香港旅游 知乎 编辑:程序博客网 时间:2024/05/21 22:53

Git常见命令总结

Git配置

新建SSH公钥

$ ssh-keygen -t rsa -C "youremail@example.com"

配置用户名和邮箱

$ git config --global user.name "Your Name"$ git config --global user.email "youremail@example.com"

新建本地仓库

创建一个新的本地仓库

$ git init

本地修改操作

修改上次提交版本的信息

$ git commit --amend

分支管理

基于当前分支新建一个分支

$ git branch <branch>

基于当前分支新建一个分支并切换到新分支

$ git checkout -b <branch>

切换分支

$ git checkout <branch>

显示全部分支信息

$ git branch -av

删除分支

$ git branch -d <branch>

多人协作

从远程仓库克隆

$ git clone git@github.com:user_name/repo_name.git

查看远程仓库信息

$ git remote -v

添加远程仓库(比如添加原作者仓库)

$ git remote add <name> <url>

删除远程仓库

$ git remote remove <name>

重命名远程仓库

$ git remote rename <old> <new>

推送分支

$ git push origin <branch>

从远程抓取分支

$ git pull 

获取远程仓库的分支和提交

$ git fetch <remote>

删除远程分支

$ git push origin --delete <branch>
原创粉丝点击