Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

James Barrett
James Barrett
13,253 Points

How to use git from another machine on a solo project

Hi there,

I want to work from another machine on my project, continuing to use version control. How do I achieve this? Here is what I think I would do:

1.) Clone the repository from GitHub 2.) Create a new branch 3.) Begin working... add and commit changes 4.) ...Here is where I get confused... How do I push it back up to the remote repo on GitHub? How would I get these permissions? 5.) After I have pushed to the remote, I can go back to my original machine and pull/clone (which one?) the latest changes and continue working as normal.

Perhaps I have missed a lot from the Git Basics course... However I think once somebody clears this up for me I will understand the process a WHOLE lot more.

Thanks, James.

3 Answers

If your project is on Github, then you already have a remote repository, which is the original repo on Github. Since Git is distributed, you can go to any computer, clone a repo from Github/Bitbucket/Gitlab, and then work with it like normal. Pushing code back is where it can vary depending on who owns the repo, and what permissions you have

Usually the credentials to do this are the username and password of your Github account. If you are using the GH client, or a tool like SourceTree, it will give you a little more visual feedback as to what is going on.

For example you could:

  1. Create a repo on github
  2. On computer 1, clone the repo, create a branch, push your branch back to github
  3. On computer 2, clone the repo, pull the branch you created down, make a change, and then push it back.

Here are specific instructions on adding a remote within Git:

https://help.github.com/articles/adding-a-remote/

James Barrett
James Barrett
13,253 Points

Hi Luke, thanks for the answer... I replied to Kevin's comment to save the hassle of posting the same thing twice. :)

Kevin Korte
Kevin Korte
28,149 Points

More or less the same process. If you were done for the night on computer1, you want to make sure you push it to the remote branch so you have access to it on computer2. Often times if my stopping point is time, (like bedtime) and not a ready to go point, i personally just decided to call those commit messages (nightly commit <and description what I'm working on/left off>). Than when I see a nightly commit, I know it's not a good bookmark, and it's certainly not complete. Make sure to push to the branch by git push origin branch-name before closing down.

Than when you get to computer2, you can fetch and merge, or pull (which is a fetch and merge done automatically by git) the remote branch, and continue your work on it.

Check out the accepted answer on this one: http://stackoverflow.com/questions/9537392/git-fetch-remote-branch

I would also highly recommend reading this: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches

In regards to your push error, I've never had it, so see if this doesn't fix it: http://stackoverflow.com/questions/20871549/error-when-push-commits-with-github-fatal-could-not-read-username

I'm just actually about a few weeks ahead of you, in coding on two different computers, so I'm just sharing my experiences. And I never did much with branches, since it was only me, but like you, I've decided to play around with branches even though on small, solo, projects it adds unnecessary complexity, it's all about learning how to integrate into larger, team based projects were branches are necessary for the future.

Hope that helps man.

Kevin Korte
Kevin Korte
28,149 Points

I do exactly what you're talking about, I work from two different computers, pushing and pulling from the remote repo on both. It ends up working quite well. I pull in changes before I start, work, and commit changes when I'm done. Than on the next computer, pull in my changes before starting, and continue.

Make sure on both computers, your pull and push streams are your remote, which you can expose by typing git remote -v. You can follow Luke's advice to setting or resetting your remote if you need to. Cloning the repo should set up your upstream and downstream correctly, but it never hurts to check.

As far as auth goes, git will ask for your github username and password each time you try to push to the remote repo. (Note: when entering your password in the terminal, it will not show any characters, not even ***, so although it looks like you are typing nothing, you are typing your password)

That's okay, but because both of my computers are pretty secure to me, I set up ssh keys on both computers, so I'm auth'ed through them, allowing me to just simply push. You can follow this: https://help.github.com/articles/checking-for-existing-ssh-keys/ to check for existing ssh keys on your computer, and than follow the links at the bottom of the page to either generate new ssh keys, or add your existing keys to your github account.

James Barrett
James Barrett
13,253 Points

Hi Kevin, thanks for the answer! So to help me understand Git more, I am going to explain a what I would do on a normal working day: 'Ok! Let's start a new project today. So I create a new repository on GitHub and add the remote as you normally would. I then create a new branch and start working away... I then decide: Alright! My feature is finished and I merge it back into master and push it to the remote. I would put my laptop away and set off for work. I then decide I want to do some of my project on my machine at work (naughty me!). I clone the repo and I add a remote using git add remote work_remote <git repo URL here> and begin working. I then work on a branch I have created, finish, merge to master and push back up (would this be where I am asked for my GitHub credentials?). After this has been done... rinse and repeat! Except now I can utilise the git pull command to pull down the latest changes.

Thanks, James.

Kevin Korte
Kevin Korte
28,149 Points

Yes, exactly! It's what I do, actually. I work on it on my laptop at home, and I always do a "nightly push" before going to bed, so when I get to work, and I want to work on the project on my work machine (guilty too), I just pull the changes down, work, commit, push back. Than I get home, rinse and repeat..(pull, work, commit, push).

The nice part is though, when you clone the remote repo to your work machine, git will automatically set up the remote URL's, and they will point to the repo you cloned, which is what you're going to want. So you shouldn't have to specifically add the remote, it should be done automatically.

And yes, from your work machine anytime git needs to do something to authenticate through github, it will ask for your login credentials unless you add the ssh keys to your github account.

In my setup, I actually have an instance of ubuntu running in a virtual box on my windows 10 work machine. This gives me two things, a Linux development environment (yay!) and in the event I need to, I simply destroy the virtual box, and everything is gone, website and all. But because it's always synced with github, I'm not worried about that.

James Barrett
James Barrett
13,253 Points

Hi Kevin,

Another scenario: If on computer 1, I finished my latest commit but I still want to work on that branch on my work computer. How would this work? Is it still the same principle? Let's say I clone the repository into my work computer and I git pull origin <name_of_branch> create a new branch... Work on it and commit the changes, how would I get this latest commit onto the remote branch?

Thanks.

James Barrett
James Barrett
13,253 Points

Ok I just tried git push (using the branch scenario I commented about last) and I get this message: https://gyazo.com/614e5e9b06e8052c986aee9212a231ce

How do I get around this?

James.

James Barrett
James Barrett
13,253 Points

Awesome! I might have a look into the virtualization technique that you use also. Thanks for the detailed answer Kevin!