1. 首先在需要查看的项目中右键选择 “Git Bash Here”,弹出命令框。
2. 输入“git remote -v”查看项目远程地址。
git remote -v
3. 通过命令先删除再添加远程仓库
git remote rm origin // 删除旧的远程地址
git remote add origin ****** // 添加新的远程地址
git branch
前面带有*号的是当前分支
$ git checkout -b other_branch
Switched to a new branch 'other_branch'
需要注意,创建分支时,不会有什么提示。
$ git branch -a
master
* other_branch
remotes/origin/master
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (master)
使用时应注意是否已合并,是否在其他分支(只有在其他分支,才能删除该分支)
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (other_branch) )
$ git branch -d other_branch
error: Cannot delete branch 'other_branch' checked out at 'D:/design-pattern-exe rcise-with-java'
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (other_branch) )
$ git checkout other_branch
Already on 'other_branch'
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (other_branch) )
$ git branch -d other_branch
error: Cannot delete branch 'other_branch' checked out at 'D:/design-pattern-exe rcise-with-java'
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (other_branch)
$ git branch -d other_branch
error: Cannot delete branch 'other_branch' checked out at 'D:/design-pattern-exercise-with-java'
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (other_branch)
$ git checkout master
Switched to branch 'master'
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (master)
$ git branch -d other_branch
Deleted branch other_branch (was c3ee210).
domin@azdebugit MINGW64 /d/design-pattern-exercise-with-java (master)
$
提示删除了一个名为other_branch的本地分支
git push origin --delete [branchname--file]
提示删除了一个名为 201804019-test-files 的分支,
注意: 在删除远程分支时,同名的本地分支并不会被删除,所以还需要单独删除本地同名分支
如果发生以下错误:
error: unable to delete ‘origin/xxxxxxxx-fixbug’: remote ref does not exist
error: failed to push some refs to ‘[email protected]:xxxxxxxx/xxxxxxxxxx.git’
解决办法:
//切换到当前分支上
git checkout xxxxx-fixbug
//然后再 进行
git push --delete origin origin/xxxxx-fixbug
此时将不会再发生错误 。
git checkout -b branchName commitId
git fetch -p
git branch | grep 'branchName'
由于每次上线,都会打一个标签,因此标签库存在多个标签。
想要删除全部的无效标签,结果执行完毕删除远程标签和删除本地标签后,发现其他同事再次推送的时候, 删除的那些标签又莫名其妙的回来了。
原因:
因为其他同事的本地标签没有清理,这时候就必须要其他同事全部都要清理本地的标签。 (很显然这行不通,很难)
解决办法:
# 使用命令一条一条的删除远程仓库.
git tag -l | xargs -n 1 git push --delete origin
# 然后再用命令清理本地仓库
git tag -l | xargs git tag -d
问题:手动添加了一个新的分支,然后push到了远程仓库,clone了一个新的,checkout时无法得到新添加的分支
原因:添加的新分支,在本地仓库没有同步
解决办法:
$ git remote update
$ git fetch
然后就可以了
$git checkout -b local-name origin/remote-name
#列出所有的标签
$>git tag --list
#创建一个标签
$>git tag
#创建一个带有注释的标签
$>git tag -a -m ‘your_tag_description’
#查看标签信息
$>git show
#查看所有的远程标签及commit ID
$>git ls-remote --tags origin
#删除一个标签
$>git tag -d
#删除远程仓库的标签
$>git push --delete origin
#推送一个标签到远程
$>git push origin
#推送多个本地标签到远程
$>git push origin --tags