Git notes

Initialize an empty Git repository in the current directory

  • git init

Set the global username and mailbox

  • git config --global user.name "name"
  • git config --global user.email "[email protected]"
  • git config user.nameView the Git user name
  • git config user.emailViewing Mailbox Configurations

Checking git Configuration

  • git config --list

Commit changes to staging

  • git add -ACommit all changes. (git add-all)
  • git add -uCommit only changes, not new files. (git add – update)
  • git add .Do not commit the deleted file
  • git add <filename>Submit specified documents

Check the staging area

  • git status

Modify the latest commit Message

  • git commit --amend

Modify a commit Message

  • git commit -i <commit id>Commit ID Is the commit ID of the parent of the target commit to be modified

Merge consecutive commits

  • git rebase -i <commit id>Commit ID is the commit ID of the target commit’s father

Commit changes to the local repository

  • git commit -m 'msg'Submit staging area to local warehouse
  • git commit -a -m 'msg'Commit changes to local repository (do not commit new files)

Viewing the Submission Record

  • git log

Adding a remote repository

  • git remote add <name> <url>

View remote warehouse information

  • git remote show <name>

Delete and rename remote repositories

  • git remote rm <remote_name>
  • git remote rename <old_name> <new_name>

Pull remote warehouse data to local

  • git pull <remote_name> <branch_name>

Commit the local repository to the remote repository

  • git push <remote_name> <branch_name>

View & Create & switch branches

  • git branchView existing branches
  • git branch -vView information about existing branches and the last submitted object for each branch
  • git branch <branch_name>Create a new empty branch
  • git branch <branch_name> <exist_branch_name>Create a new branch
  • git checkout -b <branch_name> <exist_branch_name>Create and switch to a new branch
  • git checkout <branch_name>Switch branch

Delete & merge branches

  • git branch -D <branch_name>Delete the branch
  • git merge <branch_name>The current branch merges into the specified branch

Temporary area restored to HEAD

  • git reset HEAD
  • git reset HEAD <file_name>

The workspace restores to the staging area

  • git checkout -- <file_name>
View all branches
  • git branch -a
List all (remote trace) branches
  • git branch -r
Clone Clones specified branches
  • Clone with parameters-bSpecify branch:

Git clone -b branch name https://github.com/ User name/repository name