Git基础操作导航说明
目的:
在本地fork官方项目,创建仓库。
步骤:
-
安装Git 命令,可查看Atlassian文档
-
在GitHub上Fork本仓库(获得地址此处用USERNAME)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DRX7gQ7S-1652707150813)(/Users/hoo/Desktop/Pic 0_01.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JcrAN1Ok-1652707150814)(/Users/hoo/Desktop/Pic 0_02.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-w4nSj31x-1652707150815)(/Users/hoo/Desktop/Pic 0_03.png)]
-
进入本地文件目录,Clone Fork后的个人仓库(上一步获得的地址 USERNAME 修改为自己的Git),并初始化
# fork # clone git clone https://github.com/USERNAME/faster-git.git cd faster-git git init
-
设置
upstream
仓库地址,并禁用push
(DISABLE是禁用 ABLE是可用)# set upstream git remote add upstream git@github.com:datawhalechina/faster-git.git # disable upstream push git remote set-url --push upstream DISABLE # verify git remote -v ## origin https://github.com/ShawnHoo7256/faster-git.git (fetch) ## origin https://github.com/ShawnHoo7256/faster-git.git (push) ## upstream git@github.com:datawhalechina/faster-git.git (fetch) ## upstream DISABLE (push)
-
使用分支开发,课程分支名为
lecture{#NO}
,#NO
保持两位,如lecture07
,对应课程目录# do your work git checkout -b lecture07 # edit and commit and push your changes git push -u origin lecture07
-
PR之前保持与原始仓库的同步,之后发起PR请求
# keep your fork up to date
## fetch upstream main and merge with forked main branch
git fetch upstream
git checkout main
git merge upstream/main
## rebase brach and force push
git checkout lecture07
git rebase main
git push -f
Commit Message
提交信息使用如下格式:<type>: <short summary>
<type>: <short summary>
│ │
│ └─⫸ Summary in present tense. Not capitalized. No period at the end.
│
└─⫸ Commit Type: lecture{#NO}|others
问题及解决方法:
问题1: not a git repository (or any of the parent directories): .git
解决1: 原因是git未被初始化,进入项目目录输入 git init
问题2: remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
解决2: Git取消密码登陆方式,建议查看解决方法1, 解决方法2。