Simple git example (local repository)
0. Configure your information:
1 2 | git config --global user.name "Mr User the user" git config --global user.email "mruser@theinternets.com" |
You can also configure an editor:
1 | git config --global core.editor 'vim' |
1. Create a repository
1 2 3 | mkdir testproject cd testproject git init |
2. Commit a file
1 2 3 | touch testfile git add testfile git commit |
3. Making a release branch
1 | git branch RB_1.0 master |
While you’ve created a release branch, you’re still currently on the master branch. So if you make a change here:
1 2 3 | touch testfile2 git add testfile2 git commit |
That file will NOT be in the release branch (RB_1.0).
4. Switching between the master branch and the release branch.
Unlike, SVN which stores different branches in different directories, git uses a command to switch your directory between branches. Slightly confusingly this command is called “checkout”.
1 | git checkout RB_1.0 |
If you want, you can make changes to RB_1.0, they wont be refected elsewhere.
1 2 3 | touch rb1file git add rb1file git commit |
5. Releasing
Create a tag:
1 | git tag 1.0 RB_1.0 |
List all tags:
1 | git tag |
6. Merging
Merge changes from RB_1.0 on to master:
1 2 | git checkout master git rebase RB_1.0 |
7. Delete a branch
It seems to be git practice to delete branches, you can always branch from the tag.
1 | git branch -d RB_1.0 |
8. Creating a tarball
1 | git archive -- format = tar --prefix=testproject1 1.0 > ~ /testproject1 . tar |
9. Changing a file!
This may be slightly different than you were expecting. You can’t just edit the file and type “git commit” rather, you need to add then commit. For example, after editing testfile:
1 2 | git add testfile git commit |
Git creates commits in two stages like this. The first add “stages” the change and commit commits it. You can do multiple adds before the commit. The idea is to let you get everything organised before finally performing the commit.
Notes on git
There are no version numbers. A revision is identified by its hash.
master is like trunk in SVN/CVS.
checkout, doesn’t really mean checkout. It mean switch between branches.
You can also branch from tags the same way you branch from master.
[…] repository) 12. October 2011 · Write a comment · Categories: Uncategorized In the last example we where working with a purely local repository. We’re now going to convert this to a […]