After days of coding on a project, I was ready for a vacation. I wanted a copy of my code with me on my laptop, even if it’s a vacation. In the old days, I would’ve copied the source code and patched things up later – which would be silly now because we do in fact have git. Since I never use github, I’m unexperienced with remote repositories and all the stuff that goes along with that: pull, fetch, push, remote and so on. The one feature I do know though is
First, to clone a git repository, for example on a local network server using ssh, I can run this:
git clone ssh://192.168.2.2/home/ryan/www/project/ and git will initialize the repo for me. After that and establishing the connection and providing my ssh password, it’ll clone it for me too.
I was working on a special feature when I started my vacation, but I also wanted to take my stable development branch with me too. When I raw
git branch, I didn’t see any special branches, only the head branch I was working on. To display all my branches, I had to run
git branch -a to get something like this:
ryan@ryan-laptop:~/www/public/ipo$ git branch -a
remotes/origin/HEAD -> origin/resume
Notice all of those remotes/origin things? My develop branch was one of those remote origin things. To git (get it?), I mean to get a copy to work on, I needed to make a copy of the remote branch? But how?
Getting a local working copy of a remote branch is actually easy, but the one think you need is diligence. To copy the develop branch, I ran
git checkout -b develop origin/develop. And bam!
Luckily, I don’t go on vacation very often (lucky?) so I don’t do this every day. What if I had to copy more than a single branch That’d be terrible!