Study Notes of Git

Command

remote

  • 添加远程主机

    1
    2
    # git remote add <主机名> <网址>
    git remote add origin http://bitbucket.sstparts.com/scm/web/sst-cloud.git

branch

  • 查看本地分支与远程分支的追踪关系

    -v, -vv, –verbose
    When in list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). If given twice, print the name of the upstream branch, as well (see also git remote show <remote>).

    1
    git branch -vv
  • 关联远程分支

    -u <upstream>, –set-upstream-to=<upstream>
    Set up <branchname>‘s tracking information so <upstream> is considered <branchname>‘s upstream branch. If no <branchname> is specified, then it defaults to the current branch.

    1
    2
    3
    git branch --set-upstream-to=master
    # or
    git bracch -u master
  • 分支重命名

    -m, –move

    Move/rename a branch and the corresponding reflog.

    1
    git branch -m oldBranchName newBranchName

    注意:远程分支的重命名需要通过先删除后新建的方式实现。

checkout

  • 拉取远程新分支到本地

    1
    git checkout -b 本地分支名 origin/远程分支名

    另一种方式(这种方式不会切换到新分支,需要手动切换):

    1
    git fetch origin 远程分支名:本地分支名

stash

  • 查看 stash 列表

    1
    git stash list
  • 清空 stash 列表

    1
    git stash clear
  • 删除队列中的第一个

    1
    git stash drop stash@{0}

config

git 配置有 system 级别、global 和 local 三个,优先级依次递增,也就是配置冲突时优先使用 local 级别的。

  • 查看当前仓库配置信息

    1
    git config --local --list

DIFFRENCE

  1. pull VS fetch

    pull = fetch + merge

账号管理