Git 常用命令

  1. 查看远程分支地址:git remote -v
  2. 查看远程branch:git branch -r
  3. 创建本地branch:git branch <branchname>
  4. 查看本地branch : git branch 简写 git br
  5. 切换本地分支:git checkout <branchname>
  6. 查看当前分支状态:git status
  7. 获取远程某个分支:git pull origin remotebranch:localbranch
  8. 查看git设置:git config
  9. git 更改本地仓库的远程资源库:
    1.   git remote set-url --add  origin newurl
    2.   git remote set-url --delete origin oldurl
    • 可以先add,然后git remote -v查看一下,验证添加成功了之后再删除原来的。
  10. git 本地分支关联到某个远程分支:git branch --set-upstream localtask1 origin/task1
  11. git 在windows下用url直接获取仓库,并设置用户名密码存储(不用每次pull push都在输入密码)

    1. git clone http://gitlab.com/yourproject  会提示输入账号密码下载

    2. 打开git bash 进行文件配置:

      1. cd ~
      2. vim .git-credentials
      3. 在文件中添加 http://{username}:{password}@gitlab.com
      4. 设置变量 git config --global credential.helper store
      5. 查看是否设置成功:git config --global --list 结果有这一行 credential.helper=store
      6. 重启git bash, git pull 试一下应该不用再输入账号密码了
  12. 放弃本地对某个文件的修改:git checkout filename

posted on 2015-08-16 20:21  Liz-  阅读(162)  评论(0)    收藏  举报