在vscode中使用git和github

这学期的团队项目比较多,这里📝一下常用的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。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值