首先登录,参考:记一次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`