• Global Configuration

      git config --global "your_name"
      git config --global ""
  • Configuration for project

      git config --local "your_name"
      git config --local  ""


  • Show Configuration

      git config --list --local
      git config --list --global

Add/Remove Files

  • Remove
    • git rm file_name
  • Rename
    • git mv file_name_1 file_name_2, 重命名文件


  • Add
    • git add -u, 将工作空间新增和被修改的文件添加的暂存区
    • git add ., 将工作空间被修改和被删除的文件添加到暂存区(不包含没有纳入Git管理的新增文件)
    • git add -A, stash所有修改
  • 从stash文件中删除一个
    git reset path_to_the_file


  • 参数
    • -m, commit信息
  • 恢复到上一次commit的状态
      git checkout -- .
  • 修改commit中的个人信息

      git commit --amend --author="Author Name <>"`



  • Check remote repo

      git remote -v 
  • Change repo origin

      git remote set-url origin https://xxxx.git


  • 查看分支
    • 查看本地分支,git branch -av
  • 创建新分支
    • 创建本地分支, git branch <branchName>
    • 创建远端分支,git push origin <branchName>
  • 拉取分支

      git fetch
      git checkout -b <branchName>
  • 删除分支
git branch -d <branchName>
git push origin --delete <branchName>
  • 合并
git merge branch_to_merge
  • 解决合并冲突

  • grep -lr '<<<<<<<' . | xargs git checkout --ours
  • grep -lr '<<<<<<<' . | xargs git checkout --theirs

How this works: grep will search through every file in the current directory (the .) and subdirectories recursively (the -r flag) looking for conflict markers (the string ‘«««<’)

the -l or --files-with-matches flag causes grep to output only the filename where the string was found. Scanning stops after first match, so each matched file is only output once.

The matched file names are then piped to xargs, a utility that breaks up the piped input stream into individual arguments for git checkout --ours or --theirs


  • gitk, 图形化界面