Place git repository on external hard drive
If the complete history of your project really is taking so much space (but reconsider and check twice if it really does), here could be a way to make this work:
First have your complete history in your remote
repo (external hard drive) in a branch main
(I would keep the default branch name master
, if I were you). Making it a bare repo is a good idea, to ease pushing later on. If you haven't done it already:
$ cd /mnt/your/external/drive
$ git clone --bare /repo/where/you/currently/have/the/whole/history
Then when you want to start a new development phase, take a shallow clone from remote
to local
(your laptop's hard drive)
$ cd $HOME/
$ git clone --depth 10 /mnt/you/external/drive/repo.git
This clones the repository, but only the last 10 commits are in history. That way if your history really is enormous, you'd save space (again, look twice if space taken by history really is a problem).
Create a work branch as you normally would, work in that branch, merge to main
, push to remote
:
$ git checkout -b super_feature # use good branch names, not "dev"
... work, commit, work, commit, work, commit, ... time to merge.
$ git checkout main
$ git merge super_feature # I usually add --no-ff
$ git push origin main
And there you go. You worked on your local shallow clone of your remote
, with limited history.
After a while, your shallow clone will have more and more history. If history space becomes an issue again (but... you know), just ditch the shallow clone and make a new fresh one from the remote
.
Andriko13
A solo self-taught developer, mostly making games for iOS and Android. I do find myself using python quite often however. Student by day, Code-junkie by night :)
Updated on June 04, 2022Comments
-
Andriko13 about 2 years
I am using XCODE, and have recently decided to try using git (I am a lone app developer, so never really needed to use it). Because it used to take up a lot of storage space when I tried it previously, all of my current projects with git are stored on an external hard drive. I was wondering, however, whether it is possible to keep a development branch of a project on the hard drive of the mac, while keeping the main branch on the external hard drive. That way, I can merge the stable branches every few days to the external hard drive, and keep the development copy on my macbook to remove the need to carry my external hard drive with me everywhere I go. Is this possible? Any suggestions for a newbie on git?
-
Andriko13 about 9 yearsCan you explain how to do this? I am a total newbie to source control.
-
Sam Varshavchik about 9 yearsNeither git, nor any other source control tool, can be adequately explained in a few sentences. You will find many good git tutorials by searching Google.
-
Andriko13 about 9 yearsI understand how git works. I understand merging, pushing and pulling, and the different branches you can be working with. My question is specific to the extent that I could not find any tutorials online.
-
Sam Varshavchik about 9 yearsHow much of a tutorial do you need to: 1) git clone /mnt/hard-drive/repo $HOME/repo-work-copy 2) Now, do you work in your cloned report in your home directory, and then push your commits to parent repo on the hard drive?
-
Andriko13 about 9 yearsThank you! This helped a lot, I appreciate it.
-
Silverclaw almost 6 yearsRude and unhelpful. While typing some git commands is actually trivial, understanding their implications might be helpful anyway and most tutorials don't cover those in detail.