Search code examples
gitgithubrepositorygit-pullgit-remote

I'm working on a project from two different computers. How do I simply replace the local repository with the one on GitHub?


I'm working on a project on two different computers and I want to be able to simply push from one computer and pull it on the other, so that it essentially replaces the local one with the one on Github. Just a simple replace this, with that.

I've tried looking it up, but I don't really understand the terms. I'm new to using GitHub, so I don't get merges, and branches. I just want to pick up where I left off on the other computer. I tried some solutions I found, but then I didn't understand the Merge editor, so I accidentally deleted the code in one of the files. So, I'm afraid to keep trying to use commands randomly.

If I use git clone again, will that replace all of my current files in my project to match the one on GitHub?


Solution

  • git clone will fail with an error if you try to have it overwrite an existing directory or its contents. You should only have to clone once, and if you clone then you do not need to run git init (clone does that).

    To get new work from a local computer onto GitHub (etc.),

    1. git add
    2. git commit
    3. git push

    To get new work from GitHub (etc.) onto a local computer, git pull.

    If you're switching between two systems and want them roughly up-to-date with each other, then you need to push when you finish - otherwise you'll get a message that tells you exactly what to do to fix it, but that few people actually read.