GitHub

# 查看 git 配置信息
git config --list
# 查看 git 用户名和邮箱
git config user.name
git config user.email
# 设置 git 用户名和邮箱
git config --global user.name "kongxiangyan"
git config --global user.email "[email protected]"
# 设置远程仓库
git remote add origin [email protected]:we-mobius/vue-template.git

Frequent Operations

Rename Branch Name

Git - git-branch Documentation

// 重命名本地分支
git branch -m oldBranch newBranch
// 删除远程分支
git push --delete origin oldBranch
// 推送分支
git push origin newBranch
// 设置上游分支为远程分支
git branch --set-upstream-to origin/newBranch

Modify Remote Branch

# 查看远程分支
git remote -v
# 修改远程分支地址
git remote set-url origin [email protected]:we-mobius/web-template.git

Rename Repository Name

如果托管在 GitHub 的话,首先在 GitHub 后台修改仓库名。

修改本地仓库的名字,重命名文件夹即可,如:

mv template web-template

本地仓库名字修改完成之后,将它跟远程仓库对接:

# 查看 remote 信息,此时应该是旧的地址
git remote -v

# 设置新的 remote 地址
git remote set-url origin [email protected]:we-mobius/web-template.git

# 跟踪远程分支
git branch --set-upstream-to=origin/main

# 查看 remote 信息,此时已经更新好啦
git remote -v

如果代码已经在 NPM 发布且超过 24 小时的话,需要将已经发布的包标记为“Deprecated”(npm-deprecate - npm Docs),然后用新名称重新发包。

Pull origin branch to local


Rename a file with track