Daily operation

  1. Add files to the repository
    git add
    Copy the code
  2. Add a single file to the repository
    git add test.text
    Copy the code
  3. A file with a suffix added
    git add *.html
    Copy the code
  4. Commit the repository file
    Git commit -m RemarksCopy the code
  5. Into the warehouse
    git push
    Copy the code
  6. Pull files from the warehouse
    git pull
    Copy the code

Viewing Historical Status

  1. The current state
    git status
    Copy the code
  2. Viewing Historical Records
    git log
    Copy the code

Undo modify

  1. Undo any changes that have not yet been committed
    git checkout head .
    Copy the code
  2. Undo a single suffix file that has not yet been committed
    Git checkout head *Copy the code

branch

  1. See the branch
    # View all local branches
    git branch
    
    # view all remote branches
    git branch -r
    
    View all local and remote branches
    git branch -a
    Copy the code
  2. The new branch
    Git Branch Branch nameCreate a new branch based on the remote branch and switch to itGit checkout -b origin/ remote branchCopy the code
  3. Switch branch
    Git Checkout branch nameCopy the code
  4. Delete the branch
    # delete branch (this command will fail to delete branches if they are not merged)Git branch -d Specifies the branch name# delete branchGit branch -d Specifies the branch name# delete remote branches that no longer exist
    git remote prune origin
    Copy the code
  5. Merging branches
    # If a conflict occurs, it will not be committed automaticallyGit merge specifies the branch nameCopy the code
  6. Rename branches
    # branches with the same name will not be overwrittenGit branch -m Original branch name New branch name# overwrites branches of the same nameGit branch -m Original branch name New branch nameCopy the code
  7. Establishes a trace relationship between an existing branch and a specified remote branch
    Git branch --set-upstream Name Name of the remote branchCopy the code

cloning

  1. Cloning project
    git cloneThe SSH or HTTP address of the project# ssh
    
    git clone [email protected]:songxiaoQ/test.git
    # https
    git clone https://github.com/songxiaoQ/test.git
    Copy the code
  2. Clone the code for the specified branch
    git clone-b Branch name SSH or HTTP address of the projectCopy the code

Basic Settings (initialization)

  1. Configure git accounts globally
    git config --global user.name "Your Name"
    git config --global user.email "[email protected]"
    Copy the code
  2. Query a configured Git account
    git config --global user.name
    git config --global user.email
    Copy the code
  3. Example Remove a global configuration account
    git config --global --unset user.name
    git config --global --unset user.email
    Copy the code
  4. Generating an SSH Public Key
    ssh-keygen -t rsa -C "[email protected]"
    Copy the code
  5. Initialize the Git repository
    git init
    Copy the code

Other commands

  1. Git is case-sensitive. Git on Windows is case insensitive by default

    git config core.ignorecase false
    Copy the code