1

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.

2
  • git pull means: run git fetch, then run git merge. If you want to do both, in that order, and are sure that git merge is the right thing to do immediately after git fetch, you can combine the two into one convenient git pull. I recommend keeping them separate until you are familiar with how each of the two steps work, because you will eventually find cases where you don't want to run git merge immediately, or where something goes wrong in one of the two steps and you are not sure which one failed, much less what to do about it. Commented Sep 10, 2018 at 19:53
  • Also, while it's significantly more complex (and hence probably not something you want to tackle yet), it's a good idea to separate the concept of deployment from the concept of development, and to avoid having a Git repository under the web-server directory. When you're ready for this phase, search for advice on "push to deploy github" and all of the CI/CD stuff. Commented Sep 10, 2018 at 19:56

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.