Git is a version control system (like SVN and CSV). Among Git's many powerful features, these were most attractive to me:
Please check this excellent tutorial for a high level introduction to the concepts behind Git: Understanding Git Conceptually.
Please Note: if you're using github.com as the remote repository server, just create a new repository on their website and follow their instructions.
The following procedure is taken from ”Setting up a new remote git repository”.
Set up the new bare repo on the remote server:
$ ssh myserver.com Welcome to myserver.com! $ mkdir /var/git/myapp.git && cd /var/git/myapp.git $ git --bare init Initialized empty Git repository in /var/git/myapp.git $ exit
Please note: this assumes that you have a git
user on your remote system who is authorized to log in through ssh. Also: use chmod and chown for the new directory!
On your local system, add the remote repository and push (omit git init
if you already have a local git repository):
$ cd ~/Sites/myapp $ git init $ git remote add origin ssh://git@myserver.com/var/git/myapp.git $ git push origin master
The original tutorial goes on to explain that you can specify the default remote repository by updating the git config file. However, when I checked my config file, it already contained the necessary settings for pushing and pulling to the default remote repository:
[branch "master"] remote = origin merge = refs/heads/master
Now you can simply git push
and git pull
.
To start using the GIT client for Windows you can use the following tutorial: http://nathanj.github.com/gitguide/tour.
When you get to the step Pushing to a Remote Server follow the following instructions:
Now follow the rest of the instructions as specified in the tutorial.
You can use the command git submodule
to populate a directory of your own project with a foreign repository.
Use cases:
vendor/plugins
. mod
directory.Here's a tutorial: Using git submodules to track plugins, which explains everything in great detail. This tutorial is more concise: Git Submodules: Adding, Using, Removing, Updating.
The short version:
git submodule add git@github.com:solin-repo/soda public_html/local/soda
By default, git will checkout the master branch. If you need a different branch, just move into the submodule's directory and perform a 'normal' checkout:
git checkout moodle19
Go ahead, make the changes. Move into the submodule's directory and perform the exact same git commands that you would normally use to commit and push.
To update your local repository with a remote submodule, do the following in the root of your git repository:
onno@mac-mini:~/php/kompas$ git submodule init onno@mac-mini:~/php/kompas$ git submodule update
The result:
Initialized empty Git repository in /home/onno/php/kompas/public_html/mod/soda/.git/ remote: Counting objects: 337, done. remote: Compressing objects: 100% (133/133), done. remote: Total 337 (delta 238), reused 295 (delta 196) Receiving objects: 100% (337/337), 259.68 KiB | 58 KiB/s, done. Resolving deltas: 100% (238/238), done. Submodule path 'public_html/mod/soda': checked out 'bf7200df78ff0d9a80494e30170ba04d12233e4d'
From Stack Overflow:
git config core.filemode false
From git-config(1):
core.fileMode If false, the executable bit differences between the index and the working copy are ignored; useful on broken filesystems like FAT. See git-update-index(1). True by default.
The .gitignore
file is committed to the repository - everybody using the repo is affected by it. If you want to ignore things (files, directories) locally, use: .git/info/exclude
. The exclude
file uses the same directives / instructions as the .gitignore file.
Adding a tag to a commit allows you to easily find the commit, even after a while. The tag will serve as a name that can be used besides the commit id.
To add a tag to a certain commit, you'll have to find the commit id. You can look them up with the following command:
git log
With the commit id you can create a new (local) tag:
git tag tag_name commit_id
To push the tag to the remote server you can use:
git push --tags
Here's how to push a local branch to remote:
git push --set-upstream origin new-branch
Use git grep
to search a local repository. Example:
git grep 'function get_users'
To limit the search to a subtree, specify the directory outside the commandline options, using a 'pathspec':
git grep 'function get_users' -- 'mod/usermanager'
The '–' signals the end of the commandline arguments. Please note the space between – and the pathspec.
ATTENTION: if you have a git submodule in your repo, git grep will not search this submodule. You have to descend into the submodule first.
To stop tracking a file that is currently tracked, use:
git rm --cached $THE_FILE_NAME
(and add the file name in .gitignore or .git/info/exclude).
This will not delete the actual file.