列出所有分支
- git branch
- git branch -v
- git branch -vvgit branch --merged (列出已经合并到当前分支的分支, 可删除)
- git branch --no-merged
创建分支
git branch iss53
删除分支
git branch -d testing
切换到分支 (本地工作目录会变)
git checkout iss53
创建并且切换到分支
git checkout -b iss53
合并分支, 把分支合并到当前分支
git merge hotfix
有冲突的合并
修改冲突文件, git add
git status 查看直到没有冲突
git commit
add & commit, 只 add 修改的文件
- git commit -a -m"bala"
- ---
列出远程分支
- git ls-remote
- git remote show (remote)
指定远程分支的名字
- git remote add name ...
- git clone -o name
修改远程分支地址
- git remote set-url gitlab git@gitlab.gcloud.srcb.com:mhc/gpu-infra.git
- ---
在本地新建一个 temp 分支, 并将远程 origin 仓库的 master 分支代码下载到本地 temp 分支
git fetch origin master:tmp
比较本地代码与刚刚从远程下载下来的代码的区别
git diff tmp
git pull 与 fetch 的区别
git pull 是 git fetch 和 git merge 两个步骤的结合
push & pull
git pull < 远程主机名 > < 远程分支名 >:< 本地分支名 > (如果与当前分支合并, 不写冒号后边的)
git pull origin next 等价于
git fetch origin && git merge origin/next
建立追踪 (会覆盖之前的追踪)
git branch --set-upstream-to gitlab/master tmp (不写本地分支则时当前分支)
git branch --track tmp2 gitlab/master 会新建本地分支
--------------------------------------------------------------------------------
git 配置
git 使用其他的 ssh 端口
- # cat ~/.ssh/config
- host gitlab.gcloud.srcb.com
- hostname gitlab.gcloud.srcb.com
- port 19630
代理配置
- git config --global https.proxy http://127.0.0.1:1080/
- git config --global https.proxy https://127.0.0.1:1080/
- git config --global --unset http.proxy
- git config --global --unset https.proxy
- npm config delete proxy
- git config --global http.proxy 'socks5://127.0.0.1:1080'
- git config --global https.proxy 'socks5://127.0.0.1:1080'
设置全局和局部用户
- git config --global user.name mhcvs2
- git config --global user.email merzhong0501@163.com
- git config --local user.email "merzhong0501@163.com"
- git config --local user.name "mhcvs2"
git push 免密码
cd ~ && vim .git-credentials
输入: https://{username}:{password}@github.com
git config --global credential.helper store
问题
push 失败
error: 无法推送一些引用到'https://github.com/cloud-pi/dbcm-roles.git'
提示: 更新被拒绝, 因为推送的一个分支的最新提交落后于其对应的远程分支.
提示: 检出该分支并与远程变更合并 (如'git pull'), 然后再推送. 详见
提示:'git push --help' 中的'Note about fast-forwards' 小节.
先备份一个分支 git checkout -b master_bak
删除 git branch -D master
重新拉取 git fetch origin master:master
- git checkout master
- git merge master_bak
- git push origin master
- git
来源: http://www.bubuko.com/infodetail-2633773.html