YahBoyDontKnowGit
YahBoyDontKnowGit

Reputation: 21

How does one push a local git repo to a remote git server?

For my work, I have been tasked with seeing if git (not github) will be a solid version control system for our project. I'm just trying to get a sense of how it works right now. I have never used git before besides a compsci class many moons ago in which we used a gui and github.

What I have done so far (besides install git on both machines):

Initialized a bare repo on the server

mkdir /path/to/test.git
cd /path/to/test.git
git init --bare test.git

Created a repo on local machine

mkdir testGitProject
cd testGitProject
git init

Prepared my "project"

*made some random txt files (1, 2, & 3)*
git add 1 
git add 2
git add 3
git commit -m "Initial commit, testing with three txt files"

Added remote server to local machine This is where I believe I started making mistakes

git remote add origin ssh://user@<remote_server_ip>/path/to/test.git

Attempt to push to remote server

git push origin master

I had to sign in with my ssh password and the output on my local machine indicated everything was "pushed" successfully. I tried to recreate this output but now all I see when running a push is "Everything up-to-date." I would also like to note I followed this walkthrough to create a "post-receive" hook on my local machine - not sure if that matters.

Looking at various walkthroughs and forum posts, I get very confused about live, origin, and master. I am not sure if this is just based on what you named your branches/remotes or if I need to understand them better. Both "branches" directories (on local repo and remote repo) are empty, which I assumed I'd see something there.

I feel like I understand how 65% of git works, and the other 35% I'm clueless on. I was hoping to see the three text files in my remote repo, but don't see them even when running find commands. Was this process at least somewhat close to what I need to be doing?

Upvotes: 2

Views: 90

Answers (1)

VonC
VonC

Reputation: 1323553

origin is the default name ofr a remote repository URL.
But in your tutorial, the remote URL is registered and referenced as "live".

That is because a simple git push would push, by default, to "origin".
However, updating the live server (which, as its name suggests, represents the live visible-to-all website) should be an explicit action.
By using a non-default remote name (live), you make sure a change to the live server needs more than git push: it needs git push live, making sure the user wants to impact the live server.

Since the push is done to a bare repository, it needs a post-receive hook to checkout the content of what has been pushed to the actual live website folder.

Hence the /var/repo/myproject.git/hooks/post-receive executable script with:

git --work-tree=/var/www/myproject/ --git-dir=/var/repo/myproject.git/ checkout -f

By pushing to the bare repository, you trigger the post-receive hook which, in turn, update the /var/www/myproject/ folder.

Upvotes: 1

Related Questions