Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Sunday, 10 September 2017

Installing and Using OpenGrok on Mac OS X

Background

In previous couple of posts we saw how we can setup git repositories, install git client and maintain your codebase. 
In this post we will see how to set up opengrok. This is a code base search tool that you can use to index and search your huge complex codebase. I am going to show this on my mac laptop. If you want to setup a proper server please refer to official documentation.


Installing and Using OpenGrok on Mac OS X

I am going to use Homebrew to do most of the setup here. If you are not aware of homebrew then you can read -
 Couple of things you need to install before are -
  • A servlet container like GlassFish or Tomcat to run and deploy your grok server. I will use tomcat.
  • Exuberant Ctags for analysis.
You can run following commands to set these up -
  • brew update
  • brew install tomcat
  • brew install ctags 
You can just type catalina to see tomcat is properly installed -


Next set environment variable as follows -
  • export OPENGROK_TOMCAT_BASE=/usr/local/Cellar/tomcat/8.5.20/libexec
 For path you can refer to catalina screenshot above. This environment variable will basically tell where grok needs to be deployed.

Download the latest opengrok binary from-
 I am using opengrok-1.1-rc13.tar.gz.

Next go yo your opengrok bin directory. In my case it is -
  • /Users/athakur/Documents/Softwares/opengrok-1.1-rc13/bin
and run -
  • ./OpenGrok deploy
 This will deploy grok code on your tomcat container. Now start the tomcat container




 You can now access it via -


 The error you see is ok since we have not provided our codebase source directory yet.

Noe lets add source directory. My code is in-
  •  ~/Documents/git/DataStructures
NOTE : DataStructures is a local copy of my github repo -
I am going to maintain all codebase references in
  • ~/local_repos/src/
So create a directory and add soft links as below -


 Now it's time to define your code directory that opengrok can understand. So define another environment variable -

  • export OPENGROK_INSTANCE_BASE=/Users/athakur/local_repos

That's now lets index this content. To index it go to you opengrok bin directory and run -
  • ./OpenGrok index.

You can see it automatically creates directory it needs. Just make sure it has appropriate permissions -




That's it you can refresh grok page and start searching code.


 NOTE : For every update to your actual repository or for any new repository getting added you need to call ./Opengrok index to index it. You can probably write a cron job that does an automatic pull of your repository and runs index on it.


Related Links

Sunday, 29 May 2016

Pushing existing local project to Github

Background

We have seen before how to clone a remote repository to local, work on it, modify files, commit and push to remote repository. But most of the time what happens we have a project on local (a new one) and want to save it on github. In this post we will see how to do that.



Pushing existing local project to Github

You will need to initialize a new repository on Github first. Simple create an empty repository.




Now to add your local repo you can execute following commands -
  1. mkdir MyTestRepo
  2. cd MyTestRepo/
  3. touch test.txt
  4. git init
  5. git add .
  6. git commit -m "First commit"
  7. git remote add origin https://github.com/aniket91/MyTestRepo.git
  8. git push -f origin master

Output is as follows -


You can then see this commit on remote.

After creating a new repo on github you will see following options -



Related Links

Saturday, 28 May 2016

Installing Git in Ubuntu

Background

Sometime back I had written a post about git (it's installation and usage in windows). This post simple covers it's Linux counterpart. How to install git in Ubuntu.

 Installing git on Ubuntu

To install git execute following command -
  • git apt-get install git-core

 Post installation you can run following command to verify installation -

  •  git --version


 And you are all good to go!

To set up git config you can use following command -
  •  git config --global user.name "aniket91"
  •  git config --global user.email "you@example.com"
To view the config  you can do
  •  git config --list
or view the config file
  •  cat ~/.gitconfig



Try cloning a repository
  • git clone https://github.com/aniket91/DataStructures.git

My Git Repositories


Avoid Merge Commits

Whenever you have unpushed commits on your local and you try to do a git pull after those commits it will create a merge commit .
To avoid it follow one of the below mentioned methods,

  1. run git pull --rebase 
  2. To avoid running it with the rebase flag and to make the above the default behavior when pulling changes, git config --global branch.autosetuprebase always 
  3. In SourceTree under tools->options/preferences under the Git tab select "Use rebase instead of merge by default for tracked branches"

Related Links

Friday, 17 October 2014

Install and use Git on Windows

Background

There are multiple code versioning tools. Some of them are SVN, Git, Mercurial, Perforce etc. In this post we will see how can we install git on windows and use it to create a local repository of a existing repository on github.

For installing git on Linux from source you can refer to one of my earlier posts - 


Installation

  1. Download the installer from the official git website.
  2. Run the installer. 
  3. If you are a beginner leave every setting in the installation workflow to default except probably the screen that says add git to the classath (This would alter your $PATH env variable).
  4. Finally click on finish to complete the intallation.

Screenshots for installation












Quick way to know if git is installed in your system is to open your command prompt and type git or git --version


If you see above output you have successfully installed git on your System.


Cloning a Git repository from Github

I have a repository on github that I had created fir creating a simple tic-tac-toe android application some time back. I am going to clone the same one. You can view the project at https://github.com/aniket91/TicTacToe

To clone a repository you have to use git clone repoUrl command. 
  •  C:\Users\athakur\GitSources>git clone https://github.com/aniket91/TicTacToe.git


Pushing changed to Github repository

Prior to pushing your changes you need to be aware of the changes that you have made. For that you can use git status command.

  • git status

Before pushing you need to  commit your changes. Use
  • git commit -a OR
  • git commit -m "git commit message"
to confirm your change. You will be asked to provide commit message. An empty commit message will abort the commit.



If you want to redo your commit then you need to execute - 

  • git reset --soft HEAD~1  
This will reset all your commit.

To push your changes you need to execute git push command. 

  • git push



You can see your commit changes on github. Below is the screenshot for my demo changes in this post.



Confused with master, remotes, origin?

You can run the following command to know more about repos your git knows -
  • git branch -a


Here, master is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin. remotes/origin/HEAD is the default branch for the remote named origin. This lets you simply say origin instead of origin/master.

So master is the branch name where as origin in the remote repo name.

Avoid Merge Commits

Whenever you have unpushed commits on your local and you try to do a git pull after those commits it will create a merge commit .
To avoid it follow one of the below mentioned methods,

  1. run git pull --rebase 
  2. To avoid running it with the rebase flag and to make the above the default behavior when pulling changes, git config --global branch.autosetuprebase always 
  3. In SourceTree under tools->options/preferences under the Git tab select "Use rebase instead of merge by default for tracked branches"

My Git Repositories


Related Links

Thursday, 21 November 2013

Installing Git on CentOS from sources


Installing Git on your Linux machine is very simple. Simply run sudo yum install git for Fedora/Centos or apt-get install git for Debian based systems or any package management tool you are using.

I am using CentOS Release 6.4 and the reason I am writing this post is that the version of git present in the repository is 1.7.1 whereas current version(as of 21/11/2013) is 1.8.4.3(Latest Stable Release). Thats a huge gap between versions.


Problem I faced was that I checked out HornetQ source from GitHub and then tried to import it in my Intellij IDEA. Project was imported but it failed to index it due to compatibility issues with git version.
Every time I loaded the project I got the following error -

2:53:27 PM Unsupported Git version
           The configured version of
Git is not supported: 1.7.1.0.
           The minimal supported
version is 1.7.1.1. Please update.

So I was left with no option but to download the sources and build it myself. Here is how I did it.

Firstly we need to download some tools needed for compilation and build. Simply execute the following command in your console -

sudo yum groupinstall "Development
Tools"

For git to build and run we also need dome extra dependencies. To install these dependencies run following on your console

sudo yum install zlib-devel
perl-ExtUtils-MakeMaker asciidoc xmlto openssl-devel

Now you will have to download the got source. You can do this in two ways

  1. Go to https://github.com/git/git and manually click download ZIP button than appears on the right mid of the page. OR
  2. You can use command line utility wget. Simply type following and execute in console

  Download the sources in a separate folder. Your console will look something like below



Now unzip the .zip file and navigate to master directory.

unzip git.zip
cd git-master


Now run the following commands on your console to build and install your latest git.

make configure
./configure --prefix=/usr/local
make all doc
sudo make install install-doc
install-html

Note : Generating docs may take some time.


Now you are all set with the latest git version. You can check your version executing following command on your console

git --version



For the sake of logically concluding this post which I wrote because of the problem arising in Itellij IDEA let me explain configuration changes needed in the IDE. Screen shot provided below -



Go to Files->Settings->Version Control->Git

and change the value of Path to Git Executable to /usr/local/bin/git

Where did we get /usr/local/bin/git from?

A natural question that would follow. Answer is simple. When we build our git from sources we provided an argument –prefix=/usr/local after ./configure. You can cross verify this. Simple execute the following in console

which git

This gives the location where git is installed. For me it gives -

[root@localhost aniket]# which git
/usr/local/bin/git

This path should be same for you unless you give some custom path while building sources. 


For installing git on Windows as well as knowing the basic commands you can refer to following post -


Related Links



t> UA-39527780-1 back to top