JoelAZ
JoelAZ

Reputation: 5203

How to push work to my own private repo while still pulling updates from Github?

I'm starting by telling you I'm confused. I know what I think I want to do but I'm not even sure how to go about doing it.

What I think I want to accomplish is to clone a public repo from Github but have that repo be stored on a different machine than the one I'm sitting at.

Or maybe you tell me - ...

There is a public Github repo - a template for a web app (https://github.com/WHMCS/templates-six)

I've tried searching (here, google, github help docs, others) but I think maybe the terminology keeps messing me up and I'm not finding my scenario. Between locals and remotes and clients and repos and forks I've lost my way. Or maybe it's impossible? idk.

I'd appreciate someone explaining how to do this if it can be or, if it's really just simple/basic stuff, then just point out please the right terminology at each end and I'll go back to searching it out.

Or maybe I've really scrambled it all in which case suggest a way to approximate the end result.

Thanks

Upvotes: 0

Views: 3014

Answers (2)

Code-Apprentice
Code-Apprentice

Reputation: 83527

I suggest that you read the first three chapters of Pro Git. It is free online and covers the majority of commands you need to perform tasks like this. It isn't very long. Just read a little every day and before you know it, you'll be a Git master. Eventually, you will also need to read some in the later chapters about using git on the server.

Upvotes: 0

mkasberg
mkasberg

Reputation: 17292

This is actually pretty straightforward with Git. There are many ways to do it; here is what I would do:

  1. Clone the repo onto your workstation, wherever you want the project to live. git clone [email protected]:WHMCS/templates-six.git
  2. Now, cd templates-six. From here on out, we'll be running our git commands inside this repository folder.
  3. By default, git created a remote named origin. For clarity, we're going to rename it. Run git remote rename origin github
  4. Create a bare repository on your shared hosting webserver. Call it whatever you want. There may be a way to do this in the UI, or you can do it in the terminal with something similar to git init --bare foobar.git.
  5. Back on your own workstation, add the shared webserver as a remote. You'll need to figure out the appropriate address to use here, but it should be similar to this, which uses SSH (same as you'd use to log in). git remote add webserver ssh://[email protected]:/home/joelaz/foobar.git
  6. Push master branch up to the webserver. git push webserver master:master. If that doesn't work for some reason, it should be safe to try -f, since there's no history you care about on the remote server.
  7. I'd set the upstream branch to your own webserver. git branch -u webserver/master. Now, by default, git push will push to your webserver.

With this setup, whenever you want to get updates from Github, you can git fetch github and then git merge github/master, which merges github's master branch into your own local master branch. Finally, as before, git push sends it to your webserver. You'll have to maintain the code on your workstation (which is probably a good idea anyway), and you'll make changes and fix merge conflicts there before pushing the code to webserver with git push.

To help you understand what's happening, keep in mind that each of the 3 repositories (Github, workstation, server) maintains its own copy of the code, and it's own copy of any branches. You move code between the repositories by pulling and pushing from the repository on your workstation.

Upvotes: 11

Related Questions