Adnan
Adnan

Reputation: 3337

Git fetch or Git pull to update files on a web server?

I have a local repo for a project on my computer, I have pushed it to a remote github repo. I then cloned the repo to my shared webhosting server using ssh.

I have since then made some changes on my computer, which i have pushed to github and then merged to origin (master) repo.

I would like to now update these files on my web server, but I'm a little confused about the git terminology.

Git clone X

Returns

fatal: destination path '' already exists and is not an empty directory.

Do i use git pull? git fetch? I thought these commands might download the files back to my local repo on my computer instead of the webserver.

Upvotes: 1

Views: 4413

Answers (2)

Adrian J. Moreno
Adrian J. Moreno

Reputation: 14859

If you have the master branch checked out on your production server (default for git clone) and just want to update the code in that branch, the just do a git pull.

If you move towards a workflow like git flow, then the develop branch becomes the main branch for the repository (and for git clone). You would deploy the master branch to your production environment and still do a git pull on master once all code has been merged there as part of your process.

Once you get the core branching and deployment figured out, tagging will be the next thing to implement.

Part of git flow is a release process, where you create a tag for every release. In this case, you can then checkout tag by tag to put code marked at those points throughout the master branch. Then, instead of git pull to get the current contents of master, you would checkout v1.x.x to checkout the code at different tag points. This makes it very easy to rollback a bug in production:

If v1.0.1 has a bug, then git checkout v1.0.0 to rollback. Fix the bug and then then git checkout v1.0.1.1 to deploy the hot fix or git checkout v1.0.2 to deploy the next major release.

Upvotes: 1

Petr Kozelka
Petr Kozelka

Reputation: 7980

git clone is supposed to create the clone of remote repository on your (local) directory.

You need to perform git pull on your webserver - that updates both the local repository and its attached working copy.

Using git fetch would only bring changes to your local repository, without changing the local files (which are most likely the ones server by the webserver). So this is not the one.

Upvotes: 3

Related Questions