Some reflections on working with new-to-the-company Junior Developers
It all started the other day with a git pull from the development branch of one of our projects.
CARVIEW |
Learn how to push all Git branches to a new remote without checking out each branch or modifying your working copy.
This is possible if your working copy contains the tracking branches from the old remote (origin/branch1, origin/branch1, etc.). If you do, you have the entire repo and history.
However, in my case there were dozens of branches, and some or all of them I had never checked out locally. Pushing them all seemed like a heavy lift. So, how to proceed?
I identified two options:
I could do this, and I could even write a Bash script to help. However, doing this would change my working files with each checkout, and would create a local branch for each of the remote tracking branches. This would be slow with a large repo.
There is a second alternative, which doesn't require a checkout of each branch, doesn't create extraneous branches in the working copy, and doesn't even modify the files in the working copy.
If your old, no-longer-active remote is called "oldremote" and your new remote is called "newremote", you can push just the remote tracking branches with this command:
git push newremote refs/remotes/oldremote/*:refs/heads/*
In some cases, it's also possible to push just a subset of the branches. If the branch names are namespaced with a slash (e.g., oldremote/features/branch3, oldremote/features/branch4, etc.), you can push only the remote tracking branches with names beginning with "oldremote/features":
git push newremote refs/remotes/oldremote/features/*:refs/heads/features/*
Whether you push all the branches or just some of them, Git will perform the entire operation without creating any new local branches, and without making changes to your working files. Every tracking branch that matches your pattern will be pushed to the new remote.
Like this article? Check out our top 5 Git tips and tricks
For more information on the topic, check out this thread on Stack Overflow.
It all started the other day with a git pull from the development branch of one of our projects.
Account management is often considered a branch of sales, but in reality great account management involves your entire organization.
Master the Git workflow for efficient Drupal development. Learn branching techniques, handling conflicts, and best practices for pushing changes to...
Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.