已有分支 old_branch,新建分支 new_branch
1 2 3 4 5 6
git checkout old_branch git checkout -b new_branch(包含两步:git branch new_branch、git checkout new_branch) git push origin new_branch git branch --set-upstream-to=origin/new_branch new_branch(origin/new_branch: 远程分支,new_branch:本地分支,这一步为了使两个分支产生映射,pull/push 时不用指定分支) git checkout -b ${新分支名称} [4efecaa0]
删除分支
1 2 3 4 5 6 7 8
删除时,需要切换到其他分支 1、删除本地分支 git branch -d branchName 2、删除远程分支 git push origin --delete branchName or git push origin :branchName
Git global setup
1 2 3 4 5 6 7 8
git config --list git config --global user.name "Chengfei" git config --global user.email "chengfeibi@newbanker.cn" git config --local user.name "Chengfei" git config --local user.email "chengfeibi@newbanker.cn"
Create a new repository
1 2 3 4 5 6
git clone http://gitlab.newbanker.cn/Gteam/nb-sms.git cd nb-sms touch README.md git add README.md git commit -m "add README" git push -u origin master
Existing folder
1 2 3 4 5 6
cd existing_folder git init git remote add origin http://gitlab.newbanker.cn/Gteam/nb-sms.git git add . git commit -m "Initial commit" git push -u origin master
迁移项目(Existing Git repository):连同分支和提交记录
1 2 3 4 5
cd existing_repo git remote rename origin old-origin git remote add origin http://gitlab.newbanker.cn/Gteam/nb-sms.git git push -u origin --all git push -u origin --tags
Fork 的分支拉取源项目上的修改
1 2 3 4
git remote -v git remote add upstream http://gitlab.newbanker.cn/con/marketing-uc.git git fetch upstream git merge upstream/pd-efunds
同步远程删除的分支 & 删除本地多余分支
1
https://www.cnblogs.com/saysmy/p/9166331.html
切换分支
1
git checkout -b pd-bosera origin/pd-bosera
设置密码信息
各种配置信息都在 .git/config 文件中1 2 3
bichengfeideMacBook-Pro:bichengfei.github.io bichengfei$ git clone https://bichengfei:ghp_hnQJ7kTcQQpbHKiiUw3AV0HvjdX@github.com/bichengfei/bichengfei.github.io.git bichengfeideMacBook-Pro:bichengfei.github.io bichengfei$ git config user.name "bichengfei" bichengfeideMacBook-Pro:bichengfei.github.io bichengfei$ git config user.email "1428976670@qq.com"
使用一个分支代码覆盖另一个分支
切换到 dev 分支
1
git checkout dev
设置本地分支代码的远程为 master 分支
1
git reset --hard origin/master
本地代码已覆盖,强制推送本地分支到远程
1
git push -f
完工
Git 操作
转载请注明出处。