If you can upgrade Git (to at the very least 1.8.4, but preferably to 2.16.2), you can benefit from shallow clone submodule: that will avoid cloning the full history.
git submodule add --depth 1 -- repository path
The OP adds:
For this case, I need full history to match the previous history.
We are doing this in script so the process is taking so lunch to get complete.
Since there is a --single-branch
option to git clone
, you can add your submodule in two steps, as seen here:
git clone -b myBranch --single-branch https://mygitserversuperprojecturl/server.git .submodule/server_git
git submodule add -b myBranch https://mygitserversuperprojecturl/server.git .submodule/server_git
By cloning only myBranch
, you won't clone the full 2GB repo.
By not adding --depth 1
, you will get the full history of that branch.
The OP details:
Actually here, I need full history of all branches, when I add submodule taking around 2 mins the size is (2gb) and I will create my branch1
once its done i will push my changes in my branch1 once its ok, we will checkout into the master branch and there we will push the changes all well
Then this is a job for git worktree
(Git 2.5+, so do upgrade Git first):
Clone your Git repo once, but checkout it twice, one per branch.
That way, you have two different folders with two different branches already checked out. Switching branch is then very quick, and updating those branches (git pull
) is faster than a full checkout.