Can I use git to keep a remote server up to date?

I’m using git to track a project, and if it’s possible, I’d like to set things up so git handles all my code staging, I can have a local repository for testing, and then push changes to the server with git to make them live. However, in trying to use standard git push calls, I just end up with inconsistent branching and a terrible mess of conflicting histories. Is there a way to manage staging using git?

  • How to use git when feature take long time to develop
  • Does git lfs support local or “near” secondary storage \ cache?
  • What is the difference between git rm --cached and git reset <file>?
  • How to change git submodule tracking remote branch?
  • SVN to GIT migration with branch history merging
  • How can I sort a set of git commit IDs in topological order?
  • Git contributors of each file
  • What is the state of distributed bug tracking?
  • Configure Alias on Git
  • Target Location in Sharing a Project using Egit
  • python sh library, commands with hyphen/dash
  • Git still showing deleted files after a commit
  • 2 Solutions collect form web for “Can I use git to keep a remote server up to date?”

    You have in this blog post an example of Git repo used for staging:

    IDE => local Git repository => remote bare Git repository 
                                       => Git repository with the live web application

    It involves a post-update hook on the bare repo side, in order to trigger the update of the repo on the live web server side.

    The final step is to define the “post-update” hook script on the bare repository, which is called when the bare repository receives data.
    To enable the “post-update” hook, we have to either make hooks/post-update executable or rename hooks/post-update.sample to hooks/post-update, depending on the Git version.
    In this script, we simply change to the folder of the live application, and start the pull operation:

    cd $HOME/
    unset GIT_DIR
    git pull bare master
    exec git-update-server-info

    The reason there is a bare remote repo is because it is “discouraged” to do a push into a repo with a working directory.

    Even though git is a distributed version control system, it is usually a good idea to have a central repository (could be a --bareone). It will simplify things.

    Git Baby is a git and github fan, let's start git clone.