Git版本控制(Version Control)
download link: https://git-scm.com/downloads
tutorial link: https://www.atlassian.com/git/tutorials
Initializing a new repository: git init
git init : create a new .git subdirectory in your current working directory. This will create a master branch.
Cloning an existing repository: git clone
create a copy or clone of remote repositories.
Saving changes to the repository: git add and git commit
The git add command adds a change to the staging area. However, git add doesn't actually recorded until you run git commit.
- git status : view the current branch and state of working directory
- git add <file> stage all changes in <file>
- git add <directory>
- git add . stage all files
- git add -p : y to stage the chunk, n to ignore the chunk, s to split it into small chunks, e to manually edit the chunk, and q to exit.
Git stash
Git stash temporarily saves your changes you've made to your working copy so you can work on something else.
Re-applying your stashed changes : git stash pop
Stashing untracked or ignored files*
By default, running git stash will stash
- staged chagnes
- changes tracked by git (unstaged changes)
But it will not stash:
- new files in your working copy that have not yet been staged
- files that have been ignored
.gitignore
Git sees every file in your working copy as one of three things:
- tracked - a file which has been previously staged or committed
- untracked - a file which has not been staged or committed; or
- ignored - a file which git has been explicitly told to ignore
Syncing
git remote / git fetch / git pull / git push
- git remote : create, view and delete
git config :
cheat sheet
git status : check current branch and status
git add . : stage all changes
git commit : commit changes
git commit --amend : make changes for last commit and change this commit
git checkout branchName : switch to a branch
git checkout -b newBranchName: create a new branch
git log : check log
git lg : show branches table
git push origin branchName : push your branch to remote
git push origin branchName --force : force update your remote branch
git remote -v : checkout your upstream
git branch -a : show all branches
To be continued...