Showing posts with label GIT. Show all posts
Showing posts with label GIT. Show all posts

Monday, February 4, 2013

Git branch in bash prompt in bold

If you are using git in your linux box, i'm sure that you wanted the current branch your working to be displayed some where in the bash shell so that you don't need to do a git branch. Well i learnt recently its possible to show the current working branch in your bash prompt. And i wanted it to be highlited in bold which was not the way it was by default. After doing some reading how to customize the bash prompt i was able to get it done.

First you need to have the bash auto completion package installed.

Then you need to add the following line to you .bachrc file to import the git prompt function.

source /usr/share/git-core/contrib/completion/git-prompt.sh

Then you need to customize the default prompt by adding the following line

export PS1='[\u@\h \W\[\e[1m\]$(declare -F __git_ps1 &>/dev/null && __git_ps1 " (%s)")\[\e[0m\]]\$ '

Now open a new terminal and navigate to a git repo. Your prompt will look like below.


Monday, June 20, 2011

Using GIT with Subversion

In this post I will go through how to use git together with subversion side by side. Lets say your working in project which uses subversion as the SCM. But you and your team is asked to implement a CR. Now you have a requirement to share the code between your team members while you are working on different parts of the CR. One way is to commit changes to main repo. But if you have CI this will lead to build failures which is not good. So the other option is to use a searate repo for you requirment. So I have choose git for this. Its because it will not conflict with your svn metadata. And its distributed, therefore you don't need to setup a seperate server for this.

Here how you do it:
1. First tell one of your team member to checkout the project from subversion.

2. Then create a git repo for your project.

3. Create a .gitignore file and add the following line to avoid .svn metadata folders getting into to your git repo.

.svn/

4. Now add all files you want to track onto git index. Add the rest of the files you don't like to track by git in to ignore list.

5. Then commit the changes to the git repo.

6. Now tell the other members to take a copy of your .git folder and past it into their project folder. After doing that they can do a hard reset which will sync the working tree with the git repo that was just copied.

7. Now they need to add your repo as a remote repo. You need to share your project directory to do this.

8. Then they can do a fetch and do a merge to make sure it works fine.

9. Now you could add them as remote repo as well and do step 7 to make sure its working.

10. Now you all can work on your working copy as you wish and commit things into your local repo when you think it's done and ok to share with other members.

11. To get your changes they need to do a fetch and merge.

12. If they get a conflict during the merge git will not commit the changes. So they need to resolve them before committing. One way to do it is by manually resolving the conflict by using git merge tool. Other way is checkout using --ours or --theirs options. The first will keep the original file and ignore the remote changes. The second will do the opposite. After resolving the conflicts you need to add the files into the index and commit the merge changes.

13. If change your mind and want to revert the merge because you got conflicts, then do a hard reset which revert the merge.

14. When its time to commit changes to subversion, then you can do it using your favorite subversion tool. This will not be a big task since you have the svn metadata. One thing important is to do this commit by one person always. Other wise you see conflicts because you have the same change in your working copy with different subversion metadata since you have taken those changes from git. But its matter of ignoring those conflicts since you know they are not and committing the changes you want to subversion.

If you get things configured correctly you will save lot of time in applying patch files and copy past code here and there. But if you not get it configured correctly then you will loose lot of your time on just trying to share the code. Time is money for your managment ;).

Saturday, January 8, 2011

Using GIT on windows without starting a new cmd

If you install the portable GIT from http://code.google.com/p/msysgit/ for windows you will need to set the installation path in to your PATH variable in windows. And when you start git from the command line it will open another command line which is opened in your home directory. This was something made me go crazy so i though to find away to run git within the command line i opened like i do with SVN. Well i didn't try the windows installation in msysGit site and try the same thing with the command line because i always prefer zipped installations on windows. I guess that's some thing you can try :).

So when going through the git-cmd.bat file i found away to get it running as i wanted. Here is what you need to do.

Create the following environment variable with the values :
  • git_install_root = "[folder where you extracted the zip file]"
Add the following entries to the PATH variable :
  • %git_install_root%\bin;%git_install_root%\mingw\bin;%git_install_root%\cmd;
Now open the new command line and type git. You will get the git help text :).