Thursday, May 31, 2012

Git Tip - Attaching Local Branch to Remote

So, you've just pushed your local repository off to some external server for the first time, and now you'd like to grab some changes back off that server (just like when using SVN) that you'd made from some other machine.

Except now, when git pull chastises you for now having "No remote repository specified". Gah!

Today's tip is just a quick way around this without going in an messing with config files (I've done it once, but it was a bit hairy on some of the other repositories I tried repeating the feat on, hence the advice today).

From a posting on StackOverflow, I found the following gem:
git branch --set-upstream local_branch remote/remote_branch

In practice:
- local_branch = remote_branch  --> Unless for whatever reason you've given things strange names
- remote = the short name you gave the remote repository when you added it as a remote (NOTE: this is more convenient that trying to remember and lug around those great heaping SSH-URL's that are usually needed). For me, this is either "Bitbucket" or "Github" or "Gitorious"


Now for some background.
This situation is quite common and at least for me has is the way that my current workflow for working on projects for uni work:
1) I develop the initial code using a local repository on my laptop
2) I create an online centralised repository on one of the hosting sites (these days, either Bitbucket or Github but mainly the former due to their free private repos; Gitorious is in my bad-books now due to generally unreliable and often slow service). This will act as the offsite backup/mediator/reference-implementation copy (*)
3) I push the contents of local repository to this centralised repository
4) From computer at Uni, I can then check out the latest copy of the repo from the online server, make local modifications (committing regularly), then push these back to the server when I leave.
5) Back home, I can pull the changes from the server.

(*) Due to various SSH/permissions fugliness-stuff, I've kindof given up on trying to get direct communication between my computer and the departmental servers. It would've been nice to just directly dump onto something hosted there, but this setup works well enough too...


No comments:

Post a Comment