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
Use this set of commands if you just have 1 user planned to access the repository:
mkdir /home/roq/lang/sql/myapp.git && cd /home/roq/lang/sql/myapp.git git --bare init exit
Use this set of commands if you plan to have multiple users access the repository (somegroup would be the name of the group that they all share):
mkdir /home/roq/lang/sql/myapp.git && cd /home/roq/lang/sql/myapp.git git --bare init --shared=group sudo chgrp -R somegroup . exit
copy empty remote repository locally
Note that :2094
can be dropped if you use the standard ssh
port
git clone ssh://roq@yourdomain.org:2094/home/roq/lang/sql/myapp.git
then copy your files into this newly created directory
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
add and commit files
git add . git commit -m "My first repository"
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 origin master
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 overwrite all your local files with copies from your remote repository
git fetch --all git reset --hard origin/master
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
to migrate a git repository
On new server
rsync -a -v -e ssh user@old.server.com:path/to/repository.git .
On client (you can do this or just edit the config manually)
git remote rm origin git remote add origin user@new.server.com:path/to/repository.git
A good git branching model
There is a lot of documentation on branching on the main git site, but I really like this overview;
Merging to master
git checkout release git pull origin release git checkout master git pull origin master git merge release git tag -a -m "tagged after merge" 20180102 git push origin master git push --tags origin master
Master merge with overwrite
if all else fails with a release to master merge, and you just want to $@#$@# overwrite it as per this note
git branch -m master old-master git branch -m release master git push -f origin master
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