3

My submodule repository is morethan 2 gb. whenever i do adding the submodule to my localrepo its cloning the entire submoudle remote repository.

git submodule add -f -b localbranch https://mygitserversuperprojecturl/server.git .submodule/server_git

result:- Cloning into 'submodule/server_git'...

so usually it takes morethan 1 hour to get complete could anybody help me to add particular branch without adding the entire submodule remote repo.

  git verison 1.8.3.1

Thanks.

Vinoth
  • 189
  • 1
  • 1
  • 9

1 Answers1

0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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. – Vinoth Mar 13 '18 at 13:36
  • @vinoth I have edited the answer to accommodate your requirements. – VonC Mar 13 '18 at 13:44
  • 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. (so the master branch is around 2 gb here also taking long time to checkout master) stackoverflow number - 49187351 – Vinoth Mar 15 '18 at 03:50
  • @vinoth Sure, no problem: I have edited the answer to accommodate your requirements. – VonC Mar 15 '18 at 07:03