关联本地和远程仓库

git remote add origin <remote-repo-url>

提交到远程仓库的新分支

git push origin new-branch-name

切换到某次提交

git switch --detach abc1234

关联远程仓库

# git remote add origin git@github.com:biggerwriting/brainbuild.git
git remote add origin https://github.com/biggerwriting/brainbuild.git
git branch -M main
git push -u origin main

You can use the command git remote set-url to change a remote’s URL.

未测试的命令

使用 Git Credential Helper 保存认证信息(可选) 如果你不想每次都输入用户名和 token,可以使用 Git 的凭证缓存来保存你的认证信息:

bash git config –global credential.helper cache 这将缓存你的凭证,避免每次推送时都需要重新输入。

另外,你也可以选择永久保存凭证:

bash git config –global credential.helper store 这样,你的凭证会保存在一个明文文件中(通常在 ~/.git-credentials),并在之后的推送操作中自动使用。

查看 Git 配置中的 username 和 email

查看全局配置:

git config --global user.name
git config --global user.email

这将显示全局配置中的用户名和邮箱。

查看当前仓库的配置: 如果你想查看某个特定仓库的配置(例如,如果该仓库有独立的配置),可以使用以下命令:

git config user.name
git config user.email

查看所有配置: 如果你想查看所有的 Git 配置(包括全局和仓库特定的配置),可以使用:

git config --list