这学期的团队项目比较多,这里📝一下常用的git命令,免得每次都去查
Init locally and push to GitHub
- from scrach
#config your name and email
git config --global --user.name abc
git config --global --user.email 123@abc.com
#list if you had done it
git config --global --list #show your username and email
- init locally
git init my-project#init empty git repo in current folder
#or just in the vscode gui git init
- add and commit
#stage changed means workplace to stagin area
git add *
#or
git add your-filename
#commit means staging area to your local repo
git commmit -m 'commit once'
- push to a remote repo
#you had to init a repo in github first
git remote add origin(foryour remote repos) https://your-pos.git
git push -u origin master(your-branch-name)
- pull to update
git pull
Then you can push/commit
Clone from others’ repo
- clone
git clone xxx.git
- Branches
#show all branches and where you are
git branch
# create
git branch your-branchname
# switch
git checkout another-branch
# merge
git merge branch-name# now this branch is merged to master
git branch -d newtest
# merge conflict
# after fixed
git status -s
git add fixed-file
git status -s
git commit
假设ABC都拥有一个仓库的权限,该仓库目前有master branch
如果两人都直接使用master branch,那么很有可能造成冲突,比如A删掉B需要的文件,C添加A已经实现的功能。
所以需要各自创建并切换到自己的branch,在push以前先pull当前master branch的内容,查看其他人的修改,再据此修改、提交、推送自己的内容。
如果没有权限,create pull request。
- 不过几个人的小项目也无所谓,只要会add/commit/push/pull就可以了,或者是自己本地写好上传到github。