scratch/content/html/en/blog/06_How_I_use_git.md
2010-03-30 16:39:12 +02:00

4.8 KiB

menupriority kind created_at title multiTitle multiDescription tags
1 article 2009-08-18T14:44:31+02:00 Git for self
fr en
Git en solo Git for self
fr en
J'utilise Git pour des projets personnels gérés à partir de plusieurs oridinateurs. Voici comment concilier les avantages de Git avec un workflow proche de celui de SVN. I use Git for personnal projects on many differents computers. Here is how to use almost the SVN workflow with all advantages of Git.
git
svn
workflow

<%= blogimage("central architecture","central_architecture.png") %>

I use Git 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

Now all files in the to/project/directory/ are versionned. If you want not to follow some just edit the file .gitignore fr:Maintenant tous les fichiers du répertoire to/project/directory/ sont versionnés. Si vous voulez ignorer certains fichiers il suffit de modifier le fichier .gitignore.

for example mine is:

*.swp .DS_Store ikog.py.bak output/Scratch/assets output/Scratch/en output/Scratch/fr output/Scratch/multi

Next, you want to put your project on a safe place on the net.

git clone --bare . protocol://url/of/the/repository

Now on any computer you can do:

git clone protocol://url/of/the/repository local_directory

and local_directory will contain an up-to-date project.

You should make this operation also on the computer used to create the repository. Just to verify all will be okay.

newcorps

The workflow

To resume you now have one repository on the Internet, and one or many computer associated with it. Now, what you want is to synchronize everything.

Before begining your work, the first thing to do is to get all modification from the Internet to your local host:

git pull

After that you can do (many times):

hack, hack, hack... git add some files git commit

When you want your local modification to be on the Internet just do a simple:

git push

All should be ok.

If you have some trouble with the 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 ...

Branches Synchronisation

Well, now, all seems ok, but you have to worry about two little things. Git is all about decentralisation and branches. It is very easy to manage one branch, or many branches on the same host. But synchronize branches on many hosts is not a natural operation.

This is why I created two simple scripts to automate this. One for creating a branch locally and remotely. And one to get remotely created branched on your local host.

Then when you want to create a new branch (locally and remotely) ; you simply have to do a:

git-create-new-branch branch_name

and when you are on another computer and want to get locally all the remote branches you execute:

git-get-remote-branches

Here are the code of theese two scripts:

#!/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