How can I convert all the remote branches in a local git repo into local tracking branches

GreenAsJade

How can I convert all the remote branches in a local git repo into local tracking branches, without one by one checking each one out.

One reason why you might want to do this (the reason I want to do this) is so that you can take a clone of the local repo and have in that new clone all the branches from the original remote origin.

Because "clone" only clones local branches.

Edit: a couple of scripted answers have been provided (for which - thanks!) ... I was really hoping for an in-git way, so that it is completely portable (I have users who are "windows only", and so far have survived without having to use a bash (git-bash or otherwise)).

cforbish

The best way to do this probably is with a script:

#!/bin/bash
IFS=$'\n'
for branch in `git branch -r`; do
    if [[ ${branch} =~ ^\ *(.+)/(.+)$ ]]; then
        git show-branch "${BASH_REMATCH[2]}" > /dev/null 2>&1
        if [ $? -ne 0 ]; then
            git branch ${BASH_REMATCH[2]} ${BASH_REMATCH[1]}/${BASH_REMATCH[2]}
        fi
    fi
done

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does git fetch <remote> fetch it for all the local branches tracking that remote?

From Dev

Git: How do I list local branches that are tracking remote branches that no longer exist?

From Java

Push local Git repo to new remote including all branches and tags

From Dev

Reset all branches of a local repo to be the same as remote

From Dev

Can't get remote branches to local repo

From Dev

Can I create local branches in Git without creating remote branches when I merge to remote?

From Java

Delete local Git branches after deleting them on the remote repo

From Dev

How do I delete local remote-tracking branches when remote branch is deleted?

From Dev

git bundle: two-way all branches sync between local and remote repo

From Java

How to prune local tracking branches that do not exist on remote anymore

From Dev

Restore all git branches on remote repository from local

From Java

How can I see which Git branches are tracking which remote / upstream branch?

From Java

Can "git pull --all" update all my local branches?

From Dev

How to show connections between local and remote branches in git?

From Dev

How to automatically link local git branches to remote ones?

From Dev

How to merge remote and local Git branches and retrieve lost files

From Dev

Which remote branches are my local git-svn branches bound to?

From Dev

Local branches are tidy, but all the remote branches are still there... Any suggestions?

From Java

How do I refresh branches (local/remote) in Visual Studio when using Git?

From Java

Can I delete all the local branches except the current one?

From Dev

Push all local branches to origin in git

From Dev

Pushing all local branches to other remotes in Git

From Dev

List all git local branches that start with string

From Dev

Pushing all local branches to other remotes in Git

From Dev

Git pull for all branches in local repository

From Dev

Git Fetch and Local Branches

From Dev

How to show local branches also found on remote?

From Java

Git: How do I list only local branches?

From Dev

How do I rebase a chain of local git branches?

Related Related

  1. 1

    Does git fetch <remote> fetch it for all the local branches tracking that remote?

  2. 2

    Git: How do I list local branches that are tracking remote branches that no longer exist?

  3. 3

    Push local Git repo to new remote including all branches and tags

  4. 4

    Reset all branches of a local repo to be the same as remote

  5. 5

    Can't get remote branches to local repo

  6. 6

    Can I create local branches in Git without creating remote branches when I merge to remote?

  7. 7

    Delete local Git branches after deleting them on the remote repo

  8. 8

    How do I delete local remote-tracking branches when remote branch is deleted?

  9. 9

    git bundle: two-way all branches sync between local and remote repo

  10. 10

    How to prune local tracking branches that do not exist on remote anymore

  11. 11

    Restore all git branches on remote repository from local

  12. 12

    How can I see which Git branches are tracking which remote / upstream branch?

  13. 13

    Can "git pull --all" update all my local branches?

  14. 14

    How to show connections between local and remote branches in git?

  15. 15

    How to automatically link local git branches to remote ones?

  16. 16

    How to merge remote and local Git branches and retrieve lost files

  17. 17

    Which remote branches are my local git-svn branches bound to?

  18. 18

    Local branches are tidy, but all the remote branches are still there... Any suggestions?

  19. 19

    How do I refresh branches (local/remote) in Visual Studio when using Git?

  20. 20

    Can I delete all the local branches except the current one?

  21. 21

    Push all local branches to origin in git

  22. 22

    Pushing all local branches to other remotes in Git

  23. 23

    List all git local branches that start with string

  24. 24

    Pushing all local branches to other remotes in Git

  25. 25

    Git pull for all branches in local repository

  26. 26

    Git Fetch and Local Branches

  27. 27

    How to show local branches also found on remote?

  28. 28

    Git: How do I list only local branches?

  29. 29

    How do I rebase a chain of local git branches?

HotTag

Archive