basic
initialize local repository
git init
make untracked file tracked
git add [file]
git add . # add all
git add --all
git add -A
commit changes
git commit -m "message"
view current information about git
git status
clone from the github
git clone ssh/https
git clone -b branch_name ssh/https
show commit logs
git log
reset current HEAD to specified state
# this commend will delete logs along the way
git reset --hard HEAD^ #last
git reset --hard HEAD^^ #the time before last time
git reset --hard HEAD~3
git reset --hard commit_id
revert to existing commits
# this commend will not delete any log
git revert -n HEAD^ #last
git revert -n HEAD^^ #the time before last time
git revert -n HEAD~3
git revert -n commit_id
branch
create new branch
git checkout -b branch_name
switch to another branch
git check branch_name
merge into current branch
git merge branch_name # (merge from) to the current branch (do not need to state)
undo the merge
git merge --abort
merge
remote repository
set a new remote repo
git remote add origin [https or ssh]
# origin is the default name of remote repo
view current remote repo
git remote
git remote -v
change url
git remote set-url [https or ssh]
拉取远程仓库(pull the changes from the remote)
git pull
git pull origin branch_name
>>> Already up to date.
upload
git push -u origin master # first time
git push origin master
git push remote_name local_branch_name
git push
pull request
- fork the public repo
- clone it to the local
- create new branch
- push it to the remote
- create pull request and wait for the acceptance