1. Get git on the central repo
The test location for git repos is /usr/gitroot on the test machine.
Go to /usr/gitroot and run the following:
sudo mkdir myapp.git
cd myapp.git
sudo git init --bare --shared=all
Now a new empty git repo has been created.
2. Copy existing application
Assuming on your local machine you've already created the skeleton for myapp
Go into the myapp directory and run the following:
git init
git add .
git commit
You will need to write a commit message such as "initial project check in".
This will have created the master branch.
Then push myapp to the central repo:
git push ssh://test/usr/gitroot/myapp.git '\*:\*'
3. Remove existing repo and check out central repo
The easiest thing to do now is delete the skeleton app you created and check out the app from the central repo:
cd ..
rm -rf myapp
git clone ssh://test/usr/gitroot/myapp.git myapp
4. Configure your app for git
I have a global git config (for connection to lithium) so I create a git config for the app:
cd myapp
vim .git/config
And I add:
[user]
name = rttf
email = rttf@test.com
You might want to add other configuration options.
You have to set this yourself – it's not part of the repo.
5. Create a dev branch
Depending on your application you will want to create a dev branch (dev branch is the working branch, master is the release branch):
git checkout -b dev
This will create and checkout the dev branch.
You can check which branch you're on with:
git branch
Or checkout the remote branches with:
git branch -r
Then push your new branch to the central repo:
git push origin dev
6. Using an existing application
If you're joining an ongoing project and you need to checkout an existing repo, use:
git checkout --track -b dev origin/dev
This assumes the main work is being done on the dev branch.
When updating your code you shouldn't use git pull. User git fetch first, then git merge. [This article|http://longair.net/blog/2009/04/16/git-fetch-and-merge/] explains why not to use git pull.
Including a submodule
Which we want to do for libraries/plugins.
For example, to add the core library, from the app directory:
git submodule add ssh://
git submodule init
git submodule update
Also make sure the url in the newly created .gitmodules file doesn't have your
Then commit and push any changes.
Updating submodule code
Submodules are included as a detached head. To make a change to submodule, checkout the relevant branch first, eg:
git checkout master
Then push these changes to origin.
Updating a submodule from within the parent application
From the parent application you need to add and commit (and then push to origin) the changed submodule (in other words, the fact that the submodule has changed).
Tagging
To view all tags:
git tag
To view a tag's details:
git show
To create a tag:
git tag -a
Push tags to origin:
git push --tags origin master (Normally we would only create tags on the master (release) branch.)
To update to a tag (normally from where you are deploying, stage, test or live):
git checkout
Useful commands
git describe --always --tag
git log -1 --format="%H%n%aD"