29 October 2011

Git clone from local filesystem to fetch local branches

Dan Mayer
Dan Mayer @danmayer

Github, Git, environment, So I am working on a project that has a very long test suite. Yes, that is a problem and we should start to do something about it. For now that problem exists but it leads to wanting to do some weird things. I wanted to work on code in a branch, while my tests were running in another. I had cloned the project twice so I had two versions, of the project, the issue was the branch I wanted to work in hadn’t been pushed remote. I then realized since it is git I could easily solve the problem by pointing my second version of my project at the first and fetching all of my local branches! Git is pretty great that you can solve things like this. It also means you could easily just run git off a shared network filesystem, no reason to really setup a fancy git server. Here are the steps make a second version of a project and then fetch the local branches from your first version # if you haven’t clone a second version of the project do that from the filesystem or the git server> cd project_2> git clone /Users/danmayer/projects/project_1> Cloning into project_1… # in the second version of your project add a remote repo pointing at the original version of the project on your filesystem> cd project_1> git remote add local /Users/danmayer/projects/project_1/> git fetch local> git branch #=> a list of the branches on your first projects directory This is a pretty simple thing to do, but when I ran into the issue it took me a bit of time to realize how simple it was to solve this problem. It also just illustrates just how versatile git really is.

Categories