Git tagging

Note for me, how to tag with git. Because I always forget it!

git tag -a v1.4 -m 'version 1.4'
git tag 

The first line creates a tag with the annotation (-a) v1.4 and the message (-m) “version 1.4”. And this line pushes the tag to origin master.

git push --tags

 

Mountain Lion + Git

I just installed Mac OS X Mountain Lion, as an update via the app store. Worked pretty good. After less than 30 min it was installed. Everything worked. I just missed the command line tool git.

To fix that issue I had to install the newest XCode version and XCode command line tools. The XCode command line tools you can install inside from XCode. Just go to preferences and Downloads and then you will see it.

That worked for me.

Git add, commit, push, pull

If you make changes on your local repository you can add all your changes to your local history with

git add .

With the . you add all new files to the local history. With this command you commit everything to your local git repository.

git commit -m "new changes"

You can do multiple commit. If you feel you are done and everything is good enough to share it with your co-workers you can push all your commits to the server.

git push

If you want the updates from your co-workers you have to pull the changes.

git pull

Git pull is similar to svn update.

Add a project to github

github.com is a pretty good git repository server for open source projects. If you have an account you can add easily a project to your github repo. At first generate the git project by executing this line in your project root:

git init

than add all files from your project to your local git repo:

git add .

Than commit everything to your local git repo:

git commit -m "init"

OK. Now you can connect your local git repo with your remote git repo by github.com

git remote add origin git@github.com:<username>/<projectname>.git

Just replace “username” with your github username and “projectname” with your projectname on github. Now you can push your changes to the github repo.

git push

.gitignore

If you want that git is ignoring some files for you you just have to create the “.gitignore” file in your project root. Here you can add all the files you don’t want have in your git repository. For example some meta files from IntelliJ IDEA.

*.iml
*.ipr
*.iws
.idea/

Creating a branch with git

Just go into the root directory of your project and type in:

git checkout -b branch1

That’s all. Now your created a new branch with the name “branch1”. Your working directory is now the branch.
You can commit your changes like this:

git add .
git -a -m "my changes"

After the commit you can switch to the master with this command:

git checkout master

Now you are again on the master branch. If you want to merge your two branches you can do it in this way:

git mege branch1