Broshi
Broshi

Reputation: 3592

Git local to remote and sync

I'm new to Git and I think this issue has been asked before but I'm not sure:

I'm developing on my local machine and I want to create a remote repo so that each time that I want to deploy i'll just hit git pull origin master, so:

  1. Created a local git repo on my dev machine
  2. Created a bare repo on the remote server
  3. Added a remote on the local git repo
  4. Pushed the code to the remote
  5. On the remote server > cloned the bare repo so i'll have a working copy.

That means I have a working copy on the local AND on the remote machine.

Now, when I want the remote to pull the changes, I am pushing from my local machine to the bare repo and then pulling them from bare to working on the remote?

Is it correct to have a bare repo and these two working copies will work with that bare repo?

How can I make both working copies synced [remote/local]?

When I tried to pull changes [bare > local] I got Updates were rejected because the tip of your current branch is behind

Upvotes: 0

Views: 107

Answers (1)

michas
michas

Reputation: 26495

Yes, you are correct. You need a bare repository and two non-bare ones. One on your dev box for pushing your changes and one on your server to pull them.

To sync the repositories you either do a manual pull on the second repository, or use a git hook to pull automatically after each push.

The "Updates were rejected" message should only happen when pushing to a repository which contains new commits from other people. - Please edit the question to add the exact command you typed and its output.

Upvotes: 1

Related Questions