Bhavith C Bhavith C - 8 days ago 5
Git Question

Create local respository using git same as remote respository (Local git server same as remote)

I am new to GIT

I have a remote git repository. I want to create a local repository which is same as remote (with all branches and tags same as remote).

I want to test my git commands on my local repository then I can push that to remote .

Many post I had seen where people are telling to do clone or mirror but that is not working for me .

local rep <---> remote rep
-> all branches <===> -> all branches
-> all tags <===> -> all tags


Now I want to use my local repository as server

git clone "D:\localrep\"
should have all the features (branch, tags & history) as remote server

Answer

As I already told you in the comments, git clone won't (as far as I know) automatically create all branches locally for you. You can check all branches you have in your local repository with git branch.

$ git branch
* master

Here this git repository has only one branch: the master branch. It will look like that if you clone it with git clone.
If you want to check which remote branches your local repository is aware of they exist you can have to run git branch -a. The remote branches will be of this form:

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/other_branch
  remotes/origin/branch_two

The ones with "remotes/" are the branches in the remote repository. So here you see that the remote repository origin possesses 3 branches (the lines with remotes/origin/<branch_name>) : master, other_branch and branch_two. If you want them locally as well you have to create them, with git checkout -b for example:

git checkout -b <new_local_branch> <remote_repository>/<remote_branch_name>

You replace <new_local_branch> with the name you want it to have in your local repository and <remote_repository>/<remote_branch_name> with what comes after remotes/ in the output of git branch -a.
For example to create the branch other_branch localy as a copy of the remote branch with the same name you just do:

git checkout -b other_branch origin/other_branch

then you'll see the output of git branch will be

$ git branch
 master
* other_branch

If you want to do it automatically you can create a command based on the output of git branch -a like this one:

git branch -a | grep "remotes/origin" | egrep -v "origin/(master|HEAD)$" | \
   sed "s:remotes/\([^/]\+/\(.\+\)\)$:git checkout -b \2 \1:" | bash

This one will create all branches locally except the master-branch. If there are other branches it doesn't have to create add them in the regex of egrep between the "()", separated with a "|"

Comments