首先登錄,參考:記一次github連接本地git_如何連接github-CSDN博客
SSH:
git config --global user.name "GitHubUsername"
git config --global user.email "email@example.com"ssh-keygen -t ed25519 -C "email@example.com"
# 默認保存路徑:~/.ssh/id_ed25519(私鑰)和 id_ed25519.pub(公鑰)# 復制公鑰:Github中Gettings -> SSH and GPG keys -> New SSH Key,粘貼
cat ~/.ssh/id_ed25519.pub
# 登錄檢查
ssh -T git@github.com
# 成功提示:Hi YourUsername! You've successfully authenticated...
首先拉取之前建立的倉庫:
? git clone https://github.com/JL765/Biostatistics--li.git ?
把原本存在的文件刪除掉,這個文件可以記錄本地倉庫的修改情況
將之前的博客中的代碼打包到文件夾中:【R】Dijkstra算法求最短路徑_r語言最短路徑問題-CSDN博客
加注釋說明:
echo "# 項目名稱" > README.md ?# 生成包含標題的 README.md
添加修改到緩存區
git add . # 添加所有更改
聲明修改情況:
git commit -m "Initial commit: Dijkstra算法實現"
git status ? ? ?# 確保所有變更已提交
在倉庫文件夾中右鍵打開GitBase,關聯遠程倉庫:
git remote add origin git@github.com:用戶名/倉庫名.git ?# 使用SSH地址
檢查關聯情況
git remote -v
git branch ? ? ?# 確認當前分支(如`main`或`master`)
同步更新情況
git pull --rebase
首次推送
git push -u origin 分支名
倉庫更新
git push ?# 自動推送到已關聯的遠程分支
分支
git branch -M main ?# 重命名分支
git push -u origin maingit push origin 本地分支名:遠程分支名 ?# 如 `git push origin dev:feature-dev`