git 分支常用命令

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/aiyan1111111/article/details/64906940

说明:

仅仅记录工作中常用的一些命令

总结如下:

  • 查看本地分支——git branch
  • 查看远程分支——git branch -r
  • 查看远程分支和本地当前分支——git branch -a
  • 更新分支信息(当远程发生增加、删除等时)——git fetch
  • 切换本地分支——git checkout local_branch   (local_branch为本地分支)
  • 以新建方式切换分支——git checkout -b new_branch   (new_branch为新的本地分支名)
  • 删除远程分支——git push origin 空格:remote_branch   (remote_branch为远程分支名)
  • 删除远程分支(Git v1.7.0之后可用)——git push origin --delete (remote_branch)   (remote_branch为远程分支名)
  • 删除本地分支——git branch -d local_branch   (local_branch为本地分支)
  • 强制删除本地分支——git branch -D local_branch   (local_branch为本地分支)
  • 提交本地分支到远程分支——git push origin locaol_branch:remote_branch   (local_branch为本地分支,remote_branch为远程分支名)
  • 以新建方式拉取远程分支——git fetch origin remote_branch:local_new_branch   (remote_branch为远程分支名,local_new_branch本地新建分支名)
  • 更新本地的分支——git pull origin remote_branch   (remote_branch为远程分支名)
  • 查看本地所有分支最后一次提交——git branch -v
  • 重命名本地分支——git branch -m old_branch new_branch   (old_branch为老分支名,new_branch为新分支名)
  • 合并分支——git merge from_branch   (from_branch为被合并的分支)

  • git丢弃本地修改的所有文件(新增、删除、修改)——git checkout.&& git clean-xdf
  • git初始化本地信息:——git config --global user.name "名字"                         ——git config --global user.email "邮箱"
  • git查看远程仓库信息——git remote show origin

git 修改远程仓库地址:

  1. git remote set-url origin originURL (originURL为新的远程地址)
  2. git remote rm origin
  3. git remote add origin originURL (originURL为新的远程地址)

git查看用户名、邮箱:

  • git config user.name
  • git config user.email

git修改本地用户名、邮箱:

  • git config --global user.name
  • git config --global user.email

git 撤销add的操作:

  • git reset HEAD
  • git checkout .


常见异常:

  • 当git用户名被修改后,可能导致远程仓库地址随之修改,于是会导致本地匹配不到远程仓库的问题,需要重新查看并设置一下新的远程仓库地
  • Git – fatal: Unable to create 'XXX/.git/index.lock’: File exists.的解决方法——rm -f .git/index.lock (或者rm -f git/index.lock) 删除后可提交


猜你喜欢

转载自blog.csdn.net/aiyan1111111/article/details/64906940