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:
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With