Init locally and push to GitHub
1
2
3
4
5
| #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
|
1
2
| git init my-project#init empty git repo in current folder
#or just in the vscode gui git init
|
1
2
3
4
5
6
| #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'
|
1
2
3
| #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)
|
Then you can push/commit
Clone from others’ repo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #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。