記錄下本地項(xiàng)目關(guān)聯(lián)github過(guò)程窘俺。
1. 在Github上新建項(xiàng)目
2.? 點(diǎn)擊Create repository饲帅, 跳轉(zhuǎn)頁(yè)面
3. 當(dāng)本地項(xiàng)目還未生成repository的時(shí)候复凳,cd到目錄路徑下, 執(zhí)行g(shù)it init會(huì)生成 隱藏的.git文件
由于github當(dāng)前創(chuàng)建的分支為main, 與本地的master不同灶泵,如果直接push的話會(huì)報(bào)錯(cuò)育八, 需要修改本地倉(cāng)庫(kù)branch為main
變更branch名字之后,再次push赦邻, 輸入Github的用戶名和密碼髓棋,此時(shí)報(bào)"fatal: Authentication failed for 'https://github.com/YanHuo/testTagView.git/'" 的錯(cuò)誤,意思是自從 21 年 8 月 13 后不再支持用戶名密碼的方式驗(yàn)證了惶洲,需要?jiǎng)?chuàng)建個(gè)人訪問(wèn)令牌(personal access token)按声。
解決方法: 在Github上生成令牌,步驟:Settings->Developer settings->Personal access tokens->Generate new token? 的方式得到令牌
再執(zhí)行命令
git remote set-url origin https://<令牌>@github.com/<用戶名>/<repo>.git
再次執(zhí)行? ?git push -u origin main 即可完成推送恬吕。
如果創(chuàng)建Github項(xiàng)目的時(shí)候签则,勾選了.gitignore文件會(huì)是什么情況呢?
當(dāng)執(zhí)行完上述操作后铐料, 執(zhí)行 git pull origin main 想要拉取Github上的.gitignore文件渐裂,結(jié)果報(bào)錯(cuò)了:
fatal: refusing to merge unrelated histories
此時(shí)需要加上?--allow-unrelated-histories
即:git pull origin main --allow-unrelated-histories
再次 push即可,同理push遇上同樣的錯(cuò)誤時(shí)可以 git? push -u origin main?--allow-unrelated-histories.