----- menupriority: 1 kind: article created_at: 2009-08-18T14:44:31+02:00 title: Git for self author_name: Yann Esposito author_uri: yannesposito.com tags: - git - svn - workflow ----- blogimage("central_architecture.png","central architecture") I use [Git](http://www.git-scm.org/) to manage my personnal projects. I have a centralized repository which all my computer should synchronize with. Unfortunately I didn't find clearly what I needed on the official Git documentation. In two words, if you want to use an SVN workflow with Git (and all its advantages) here is how to proceed. newcorps ## Initialisation Suppose I've got a directory on my local computer containing a project I want to manage via Git. Here what to do:
cd to/project/directory/
git init
git add
git commit
to/project/directory/
are versionned.
If you want not to follow some just edit the file .gitignore
for example mine is:
*.swp
.DS_Store
ikog.py.bak
output/Scratch/assets
output/Scratch/en
output/Scratch/fr
output/Scratch/multi
git clone --bare . /path/to/repository
git clone protocol://path/to/repository local_directory
local_directory
will contain an up-to-date project.
git pull
hack, hack, hack...
git add some files
git commit
git push
push
and pull
verify your .git/config
file ; it should contain the following lines:
...
[remote "origin"]
url = protocol://url/of/the/repository
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
...
git-create-new-branch branch_name
git-get-remote-branches
#!/usr/bin/env zsh
if (($#<1)); then
print -- "usage: $0:t branch_name" >&2
exit 1
fi
branch=$1
git br ${branch}
git co ${branch}
git config branch.${branch}.remote origin
git config branch.${branch}.merge refs/heads/${branch}
#!/usr/bin/env zsh
# recup branches not on local
localbranches=( $(git br | sed 's/\*/ /') )
remoteMissingBranches=( $(git br -r | \
egrep -v "origin/HEAD|(${(j:|:)localbranches})" ) )
for br in $remoteMissingBranches; do
branch=${br#origin/}
print "get remote branch $branch"
git br ${branch}
git config branch.${branch}.remote origin
git config branch.${branch}.merge refs/heads/${branch}
done