How To Create and Use a Remote git Repository

git is a version-control system, that is very powerful, and pretty easy to use. There are many advanced tutorials on it's use, here are a simple bunch of commands that I commonly use.

  • on your remote server, create a space for the remote repository

    mkdir /home/roq/lang/sql/myapp.git && cd /home/roq/lang/sql/myapp.git
    git --bare init
    exit
        

  • create git repository and add files to it

    git init
    git add .
    git commit -m "My first repository"
        

  • add location of remote repository

    Note that :2094 can be dropped if you use the standard ssh port

    git remote add origin ssh://roq@yourdomain.org:2094/home/roq/lang/sql/myapp.git
        

  • push local repository onto your remote repository

    git push origin master
        

  • to make changes to your files, first

    git checkout master
        

    ...then make your changes

  • once you're done, push your changes back to the remote repository

    git commit -a -m "Next release"
        

  • to collect changes made by others from the remote repository

    git pull origin master
        

  • to remove a file from the git repository (actually, it makes git forget about the file) - note that this will actually delete the physical file if it's still there

    git rm OLDFILE
        

  • for someone else to create a copy of your repository

    git clone ssh://roq@yourdomain.org:2094/home/roq/lang/sql/myapp.git
        

  • to get the latest from the remote repository

    git pull
        

  • to exclude files or directories

    edit the .git/info/exlude file, for example, here I wanted to exclude all subdirectories that start with 2009 and a few other files that I needed in that directory, but didn't want checked-in:

    2009*
    *.pl
    *.exe
    *.lnk
        

  • to keep your "remote" repository on a USB key

    Note that you'd still have to create the directory on your USB key and run git --bare init from within that directory. Here I have a remote repository on a TrueCrypt volume that I always mount as M: on Windows:

    git remote add origin /m/git_repository/myapp.git
        

    On Linux, I mount the same TrueCrypt volume as /media/truecrypt1:

    git remote add origin /media/truecrypt1/git_repository/myapp.git
        

    More Questions?

    What else can git do? : Here are some more pages.

    Git for Windows : An Illustrated Guide to Git on Windows

    A Guide for Intermediate Git users : http://andyjeffries.co.uk/articles/25-tips-for-intermediate-git-users

    Using Git with a central repository : http://toroid.org/ams/git-central-repo-howto

    Something cool : Git Bundle

  •  © Roqet 2012-01-16 08:29:14   Content :: Contact :: About RoqWiki