git init
to init a working space into a git repogit add filename
orgit add .
to track file or all files, and add them to stagegit commit -m "message"
to commit changes to local repo- Several files can be commited together:
git add file1; git add file2; git commit -m "add 2 files"
- Use regx:
git add "*.txt"; git commit -m "add all text"
git status
to check which file has been modifiedgit diff filename
to check details of modification in filenamegit log
to show logsgit log --pretty
to show concise info of log,git log --graph --pretty=online --abbrev-commit
for more infogit reset --hard HEAD^
to recover to last commitgit reset --hard ID
to recover to specific versiongit checkout -- filename
to dismiss modification in local working space, e.g. if you delete text.txt in working space and want to recover it,git checkout -- text.txt
can pull it from local repo to working spacegit reset HEAD filename
to recover file from local reporm filename
to delete file in working space, only phisically delete the file without loggit rm filename
to delete file in working space and add a deletion operation in log waiting for commitgit remote add origin **https**
to connect to a remote repogit push -u origin master
to push local repo to remote repo.-u
for first push, it will connect local and remote repo for pull and push in futuregit clone **https**
to clone a remote repo to local positiongit checkout -b dev
create a new branch named dev, and switch to it. This command equals togit branch dev; git checkout dev
git branch
to check current branchgit merge dev
to merge modification from dev to current branchgit branch -d dev
to delete branch devgit merge
is Fast Forward mode which will lose merge log,git merge --no-ff -m "merge with no-ff"
will keep the merge log and make a new commit(so it needs a -m), with –no-ff you can see the merge in log
Bug Branch
git stash
to keep current working space
git stash
git checkout master
git checkout -b bug-101
*fix the but*
git add .
git commit -m 'fix but-101'
git checkout master
git merge --no-ff 'merge bug-101 fix' bug-101
git branch -d but-101
git checkout dev #return to previous working branch
git stash list #check kept working space, e.g. *stash@{0}: ...
git stash apply stash@{0} #recover the working space without delete it in the list
**or**
git stash pop stash@{0} #recover and delete it in the list
`</pre>
### Omit unmerged Branch
<pre>`git checkout -b new-feature #new branch for feature development
git add featurefile
git commit -m "add new feature"
git checkout dev
*requirement changed, the feature is dismissed*
*new feature has not been merged, so need force Delete*
git branch -D new-feature
`</pre>
### Coordination
<pre>`git remote #return remote repo name, e.g. origin
git remote -v #return details
git push origin dev #push current branch to origin dev
git checkout -b dev origin/dev #create a dev, and push it to origin/dev
git pull #git fetch and merge to current branch