更新
2022.11.18
文章更新内容:
1.github上创建的git branch的名字是main,不是原来的master, 第6步和第7步
git pull --rebase origin main
git push -u origin main
2.提交时需要使用PAT(personal access token)验证,不是之前的用户名加密码
注意,在提交本地项目时,如果使用用户名和密码会有如下提示
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/wayne214/componentization_demo/'
根据提示,在github官网添加pat, 之后使用用户名和pat就可以正常提交了
附:创建Pat链接
3.如遇报错error: src refspec main does not match any
使用如下命令解决:
$ git branch -M main
开发步骤
其实就几个步骤:
1.在电脑上创建一个新的文件夹
2、(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库
git init
3、把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点“.”,意为添加文件夹下的所有文件
git add .
4、用命令 git commit告诉Git,把文件提交到仓库。引号内为提交说明
git commit -m 'first commit'
5、关联到远程库(这里我用的是HHS协议)
git remote add origin 你的远程库地址
如:git remote add origin git@github.com:wayne214/demo.git
如果执行到这步提示出错信息:fatal: remote origin already exists
解决办法:
1、先输入$git remote rm origin
2、再输入 $git remote add origin git@github.com:lily000000/demo.git 就不会报错了!
6、获取远程库与本地同步合并(如果远程库不为空必须做这一步,否则后面的提交会失败)
git pull --rebase origin master
7、把本地库的内容推送到远程,使用 git push命令。
git push -u origin master
总结
新建项目
echo "# android_demos" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/wayne214/android_demos.git
git push -u origin main
已有项目
git remote add origin https://github.com/wayne214/android_demos.git
git branch -M main
git push -u origin main
欢迎关注订阅公号[君伟说],备注“技术交流”,邀请入群