git related operations

Posted Jun 16, 20202 min read

git repository

  • local files
  • Cache area(git add command can add items to the cache area)
  • Local repository(git commit can be added to local repository)
  • Remote warehouse(git push pushes local warehouse files to remote warehouse)

Initialize the git project and commit

  • git init
  • echo'# project name' >> README.md //write content
  • git add README.md or git add . add files for tracking
  • git commit -m "commmit info"
  • git push orgin master

Local modification, conflict with remote

  • git stash to backup local files
  • git pull origin master pull remote files
  • git stash pop launches backup files to resolve conflicts

Delete the folder on the remote branch, but keep the folder on the local branch

  • git rm <delete file path> needs to delete the file in the staging area or branch, and the work area does not need this file anymore
  • git rm --cached -r <delete folder path> needs to delete the file in the staging area or branch, but does not want the workspace to delete this file
  • git commit -m'delete folder'
  • git push orgin master

Pull

  • git fetch user pulls the latest remote content to the local, the user checks whether they want to merge into the local working branch
  • git pull users pull remote content to local and force merge, equivalent to git fetch + git merge
  • git fetch <remote host name> <branch name>
  • git pull <remote host name> <remote branch name>:<local branch name> pull content from remote branch to local branch
  • git branch to view all local branches
  • git branch -r view all remote branches
  • git branch -a view all local and remote branches
  • git branch <branchname> New branch
  • git checkout newBranch switches to your new branch
  • git checkout -b newBranch creates and switches to a new branch
  • git push origin newBranch will post a new branch on github
  • git branch -d <branchname> delete local branch
  • git push origin :newBranch deletes a branch on the remote end of github(the colon before the branch name represents deletion)
  • git branch -m <oldbranch> <newbranch> rename the local branch

Common commands

  • git status to view the current git status(with several file modifications and several new additions)
  • git diff to see where all files have been modified
  • git checkout [filepath] pull and delete specific files deleted locally
  • git remote -v to view the remote version
  • git merge <branch name> merges the contents of the specified branch into the current branch
  • ssh-keygen -p delete ssh password
  • git reset [filename] Undo the operation of adding a file, if it follows the file name then undo this file, if it does not follow the file name then undo all

Reducer correspondence

  • -d => --delete delete
  • -D => --delete --force force delete
  • -f => --force force
  • -m => --move move or rename
  • -M => --move --force Force move or rename
  • -r => --remote remote
  • -a => --all all