Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the fastest way to work in git over a slow network connection?

Tags:

git

vpn

Here's the scenario: At work we have quite a few branches and we haven't kept the repo as tidy as we should, occasionally adding/removing large files or whatnot, and rarely removing dead branches.

So today is a snow day and I have to work from home. I have a slow VPN connection, and all I need is the fastest way to get to the one branch I care about and start working, with the ability to push commits back.

In SVN, I would have just updated the paths/files I needed and would have been working in no time. Like most git newbies, I only have a handful of trusted commands, and my fallback git clone or git pull are going to be too slow.

So it seems to be a two part question:

  1. How do I clone a repo to get working as quickly as possible, and
  2. How do I pull/push from this repo (edit, commit, pull, push)

Working solution (per @g19fanatic's suggestions below):

> git clone -b <branchname> <repo_url> --depth=1
remote: Counting objects: 16679, done.
remote: Compressing objects: 100% (11926/11926), done.
remote: Total 16679 (delta 6936), reused 10919 (delta 3337)
Receiving objects: 100% (16679/16679), 628.12 MiB | 430 KiB/s, done.
Resolving deltas: 100% (6936/6936), done.
> git pull
Already up-to-date.

(make small change on other machine, commit/push)

> git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 0 (delta 0)

Excellent, this left me with a working repo.

The only issue is that it transferred twice as much data initially as the below failed attempts did, but it did leave the repo in a usable state. I'll considered this answered, but I think there could be improvement on the initial transfer size.

like image 782
Jeff Ward Avatar asked Nov 02 '11 18:11

Jeff Ward


1 Answers

Doing a little test here, i was able to do the following...

We have a shared --bare repo out on the network

i have the remote setup as git remote add origin <pathToSharedRepo>
i do a git pull origin <branch> --depth=1 (not at git fetch but git pull)

this successfully pulls only the "HEAD + depth" commits for this branch. I can do commits to this and the such and then push (git push should work just fine) it back out without issue.

to pull the new commits and JUST the new commits from the shared repo, i have to explicitly type git pull origin <branch>. Since this is the way I originally did the pull (explicitly), I have to do the same this time...

This should not pull down any more history than the depth you originally set (it doesnt care)


To be complete, you can also do a depth setting when you're cloning the repo:
git clone -b <branch> <pathToRepo> --depth=<numCommitsWanted>

like image 147
g19fanatic Avatar answered Oct 11 '22 19:10

g19fanatic