We could push each local branch separately, but pushing all branches at once would be much faster by executing the following Git command: git push -all new-origin Now we are ready to push all local branches and tags to the new remote named new-origin.
The name origin refers to the original remote repository by convention, it is considered the primary centralized repository.) (Git has this concept of “remotes,” which are simply URLs to other copies of your repository. Let’s use the SSH-cloned URL of our new repository to create a new remote in our existing local repository by executing the following command: git remote add new-origin will give us two remotes for the existing repository: the original one (named origin, connected to the existing remote host) and a new one (named new-origin, connected to the new host). If not, create a new repository, and then you will have its SSH-cloned URL. Now we know for sure that all branches in our repository are stored locally, and we are ready to move the repository to a new host.Īt this point, let’s assume we have an SSH-cloned URL of our new repository. Git checkout -b release/0.1 origin/release/0.1Īfter creating local copies of everything, we can verify once again whether all branches with the remotes/origin/ prefix have corresponding local copies (shown without the prefix): git branch -a
That’s OK - let’s just create local copies: git checkout -b develop origin/develop So, only our master branch is local, whereas remotes/origin/develop and remotes/origin/release/0.1 are not. We can easily tell from this output whether we have local copies of all remote branches: The remote ones are prefixed with the remotes/origin/ path, and the local ones aren’t. Let’s list all existing branches (local and remote) to see whether we are missing any copies locally: git branch -a We can check for any missing branches that we need to create a local copy of. And a local copy is required to migrate the repository.
#GIT CREATE BRANCH AND PUSH TO SERVER HOW TO#
Let’s Learn How To Do That Properlyįirst, we have to fetch all of the remote branches and tags from the existing repository to our local index: git fetch originīut even if all branches and tags have been fetched and exist in a local index, we still won’t have a copy of them that is physically local. The most important thing is to make sure that your branches and tags and your commit history are all moved. I thought, then, that every developer would benefit from knowing how to migrate a Git repository to a new host quickly and easily. Having made many attempts, and a couple of fails, and carefully reading Git’s documentation, I found a solid and effective way. When I had to move a number of Git projects to a new host, it took me quite some time to find an accurate method. Suppose your company decides to change its code-hosting provider or you wish to move your own Git repository to a different host.