reference link: msdn(微软提供的github学习教程 os: 微软啥都教...)
- init local repo
git init
- create github repo
- push your local repo to github repo
git push
- os: 直接看链接吧,不搬轮子了
- Can't use
git push
from my terminal
os: config ssh and something other... daunt me really...
- about git(github上对git的介绍)
- git-reference(git官网命令行参考手册 os: 我就看了几分钟,啃不动硌牙)
- Pro Git(很详细的官方推荐书籍,只用看前几章就可以了 os: 这个倒可以花时间认真看看,写得不错)
因为git版本更新具有backward compatibility,所以很多指令的功能有所重叠,建议选择最直观常用的指令记忆
git add
git commit [-m] [-a]
git diff [--staged]
git status [--short]
git rm [-f] [--cache](--cache指明从staged area删除该文件但不从working directory删除文件)
git mv (用来对文件进行重命名)
git init
git clone
git config
git push
git log [--patch] [--stat]
[--pretty=oneline(short/full/fuller/format:"%h - %an, %ar : %s")]
[--graph] [-<n>](e.g. -2) [--since=2.weeks] [--until=] [--auther] [--grep]
[-S <string>] (pickax option, 用来显示指定字符串次数改变的commit os: 建议通过实例理解)
[-- <path>] (重要,用于显示路径文件或文件夹更改过的commit)
e.g. (os: 经典叠buff)
For example, if you want to see which commits modifying test files in the Git source code history were committed by Junio Hamano in the month of October 2008 and are not merge commits, you can run something like this:
git log --pretty="%h - %s" --author='Junio C Hamano' --since="2008-10-01" \
--before="2008-11-01" --no-merges -- t/
git commit [--amend] (对上次commit进行修补工作)
git restore(对working directory进行恢复) [--staged](对staged area进行恢复)
git remote [-v] (显示URLs)
git remote add <shortname> <url>
git fetch <remote>
git pull (在fetch基础上进行merge, 如果pull.febase变量没有设定则会给出警告)
git config --global pull.rebase "true" (pulling时进行rebase)
git push <remote> <branch> (如果和别人同时clone后而别人先push的话你再push就会被reject, 你需要fetch后incorporate别人代码后再push)
git remote show <remote>
git remote rename <remote> <new_remote>
git remote remove <remote>
git config --global alias.<alias> <command>
(e.g. git config --global alias.st status, you can type git last
instead git 'git log -1 HEAD'
)
git config -global credential.helper cache
(using HTTPS URL to push and don't wanna to type password everytime, see more in credential storage)
git branch <branch> (create a new branch)
git branch -d <branch> (delete a branch)
git checkout <branch> (switch to a new branch)
git checkout -b <branch> (create and switch to a new branch)
git log --oneline --decorate --graph --all (paint a tree with all branches. os: cool!!!)
git switch [-c/--create] <branch>
git swtich - (switch to previous branch)
git merge <branch> (e.g. git check out master | git merge hotfix)
git merge --abort (abort the merge)
git mergetool (graphical tool to resolve issues)
git branch [-v] (list all exiting branches) [-all] (including remote branches)
git branch [--merged/--no_merged]
git branch --move <old_branch_name> <new_branch_name> (change the name of branch)
git push --set-upstream origin <new_branch_name> (push new/rename branch to remote)
git push <origin> --delete <branch>
branches name like origin/main
git fetch <remote> (get remote database without omit)
git push <remote> <branch>:<branch_newname>(':'以及后面部分可省略)
git merge <remote/branch> (merge remote work to current working branch)
git checkout -b <branch> <remote/branch> (create a new branch that you can work on)