I need help with downloading all my GitHub repos at once. I have around 10 different repositories and want to get everything including all branches and commit history.
Right now when I use the download ZIP option on GitHub’s website, it only gives me files from one repo at a time and just the current branch. This doesn’t include the git history or other branches.
I tried using git clone https://github.com/myusername/ProjectDemo.git but this only pulls the main branch. I need all branches from all my repos.
Is there a simple script or command I can use? I don’t mind copying and pasting repo names manually since I only have about 10 of them. I’m looking for something straightforward that will grab everything including the full git history for each repository.
hey! if u clone the repo, it gets every branch. just check them out using git branch -r to see all remote branches, then git checkout branchname. u can also use git fetch --all and git pull --all to keep everything up to date. good luck!
I wrote a Python script for this exact thing when I switched jobs and needed to backup my whole GitHub account. Just use the requests library to hit GitHub’s API, then subprocess for git commands. Get your repo list from the API, loop through each one, and run git clone --mirror - this grabs everything including all branches and tags. The mirror flag is key here because it preserves everything exactly like it is on GitHub. You can always convert these mirrors to normal repos later with regular git clone. Way more reliable than cloning normally and trying to fetch all branches afterward, plus you get a perfect backup of everything.
GitHub CLI makes this way cleaner. Install it with gh auth login, then run gh repo list --limit 100 to see all your repos. Write a quick bash script to clone each one. Use git clone --mirror instead of regular clone - it grabs everything at once (all branches, tags, complete history). Mirror creates a bare repo with all the references and objects. Need working directories later? Just clone from your local mirrors. This has saved me tons of time backing up projects, especially since it keeps all the git metadata that ZIP downloads throw away.
Use git clone --recurse-submodules then run git fetch --all && git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done after cloning. This pulls all remote branches locally - no need to manually checkout each one like other answers suggest.