views:

1452

answers:

3

I am developing some school grading software and decided to use Github to host the project. After building some code on my Ubuntu box I pushed it to Github and then cloned it down to my MacBook Pro. After editing the code on the MBP I pushed it back to Github. The next morning I tried to update my repo on the Ubuntu box with a git pull and it gave me all kinds of trouble.

Whats the best way to work in this situation? I don't want to fork my own repo and I don't really want to send myself emails or pull requests. Why can't I just treat Github like a master and push/pull from it onto all of my personal repos on different computers?

Thanx!

A: 

What kind of trouble did it give you? The workflow you just outlined is exactly how I work on projects where I am the lone developer.

Daniel Lucraft
+5  A: 

I'll assume your problem was that the machine on which you first created the repo crapped out when you tried to issue the git pull command.

When you clone an existing git repository (like you did on your 2nd machine, the MacBook Pro), you're automatically set up to so your git pull commands will automatically merge the remote with your local changes.

However, when you initially create a repo and then share it on a remote repository, you have to issue a few commands to make things as automated as a on cloned repo.

# GitHub gives you that instruction, you've already done that
# git remote add origin [email protected]:user_name/repo_name.git

# GitHub doesn't specify the following instructions
git config branch.master.remote origin
git config branch.master.merge refs/heads/master

These last few instructions configure git so future git pull's from this repo will merge all remote changes automatically.

The following is a bit of shameless self-promotion. If you use Ruby, I have created a Ruby-based tool that lets you deal with all these kinds of things with git remote branches. The tool is called, unsurprisingly, git_remote_branch :-)

If you don't use Ruby, my tool is probably gonna be too much of a hassle to install. What you can do is look at an old post on my blog, where most of the stuff grb can do for you was explicitly shown. Whip out your git notes file :-)

webmat
This was exactly what I was looking for. I am using Ruby, but I am trying to learn my way around Git as well and I think that doing it the "hard way" is probably best right now. :)
RNHurt
That's exactly the point of git_remote_branch. Each time it runs a command on your behalf, it prints out the commands it's running for you in red. Also, it can be used as a cheatsheet with the explain command: grb explain create new_branch (instead of the normal command grb create new_branch) :-)
webmat
“GRB: It doesn’t just stand for Gamma Ray Burst any more.”
Aristotle Pagaltzis
+2  A: 

You can also add multiple SSH public keys.

dylanfm