美文网首页
git拉取远程所有分支代码到本地

git拉取远程所有分支代码到本地

作者: 炫子_260f | 来源:发表于2022-03-17 10:52 被阅读0次
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

转自
git拉取远程所有分支代码到本地

为指定仓库设置多个远程地址

git remote set-url --add <name> <url>

示例

  1. origin 添加一个链接 git remote set-url --add origin https://github.com/tingtingtina/xxx.git
  2. 这时通过git remote -v查看信息origin 这个仓库下就有配有多个地址了,当 git push 的时候(默认是 origin,也可指定<name>)这个名下所有的远程仓库都会被更新。
$ git remote -v
origin  http://git.xxx (fetch)
origin  http://git.xxx (push)
origin  https://github.com/tingtingtina/xxx.git (push)

改写历史,去除大文件

查看存储中的大文件

git rev-list --objects --all | grep -E `git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -10 | awk '{print$1}' | sed ':a;N;$!ba;s/\n/|/g'`

git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -15 | awk '{print$1}')"

eg

git rev-list --objects --all | grep e9e4f5bee25e0f3323f8d4a83505c25293018ad1

注意:下方命令中的 path/to/large/files 是大文件所在的路径,千万不要弄错!

git filter-branch --tree-filter 'rm -f path/to/large/files' --tag-name-filter cat -- --all
git push origin --tags --force
git push origin --all --force

出现异常

WARNING: git-filter-branch has a glut of gotchas generating mangled history
         rewrites.  Hit Ctrl-C before proceeding to abort, then use an
         alternative filtering tool such as 'git filter-repo'
         (https://github.com/newren/git-filter-repo/) instead.  See the
         filter-branch manual page for more details; to squelch this warning,
         set FILTER_BRANCH_SQUELCH_WARNING=1.
Proceeding with filter-branch...

Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f

解决方法:
您已经执行了筛选分支操作。在过滤分支之后,Git保留对旧提交的引用,以防出现问题。

你可以在.git/refs/original/…中找到。或者删除该目录和其中的所有文件,或者使用-f标志强制git删除旧的引用。

git filter-branch -f \
--index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD

相关文章

  • git操作

    1.git pull拉取远程分支到本地 $ git pull <远程主机名> <远程分支名>:<本地分支名> 如拉...

  • git 常用命令

    git 拉取远程分支到本地 git checkout -b x origin/x 拉取远程分支并同时创建对应...

  • git 命令相关

    1,查看所有远程分支:%git branch -r 2, 拉取远程分支并创建本地分支git checkout -...

  • git 按需拉取

    普通的方式 拉取的是所有分支的代码: 基于远程分支(master)新建本地分支(master): git chec...

  • Git常用操作场景

    1,拉取远程分支到本地(本地不存在的分支) git checkout -b 本地分支名 origin/远程分支名 ...

  • git拉取远程所有分支代码到本地

    转自git拉取远程所有分支代码到本地[https://www.jianshu.com/p/c196df31322b...

  • 同步同事提交的git代码到本地

    git拉取远程分支文件 拉取远程分支 git fetch <远程主机名> <分支名> 取回更新并在本地创建新的分支...

  • git 相关命令学习

    本地分支指向新的远程分支 切换到新的远程分支拉取最新代码 切换到本地分支 git branch --unset-u...

  • git拉取远程分支并创建本地分支

    一、查看远程分支 Git命令查看所有远程分支: 二、拉取远程分支并创建本地分支 方法一 使用如下命令:git ch...

  • git拉取远程分支并创建本地分支

    一、查看远程分支git branch -r 二、拉取远程分支并创建本地分支git checkout -b 本地分支...

网友评论

      本文标题:git拉取远程所有分支代码到本地

      本文链接:https://www.haomeiwen.com/subject/ddrvdrtx.html