Thursday, January 8, 2015

How to change the URL of git remote origin

URL of the current remote origin can be simply changed with the command:
git remote set-url origin <new_git_url>
<new_git_url> could be any valid remote git url. Like
ssh://user@host:1234/srv/git/example
or
https://github.com/rtbkit/rtbkit.wiki.git
etc






SSH Server as the Git Repo

I have been using Dropbox as my private git repository. as discussed in HERE Similar to this, Google Drive can also be used as the git repository.

Problem

The problem is, when we are syncing the Dropbox (or Google Drive) in two machines, we are going to have Copy of Git Repo in two different machines. Even worse, if you decide to share the Repo with your friends, then the Repo is going to exist in multiple machines. Now imagine a situation, multiple users make a change to theie individual repo and sync at the same time. At such instance, when the Dropbox syncs, changes from one machine will be saved but others will be overriden.

So if you want to use Dropbox (or Google Drive) as SSH Repo server, then only one user can make change to the repo at a time. If another user (or machine) wants to make a change, he has to sync first and make sure that nobody else makes any change.

SSH - The Savior

It is also possible to use SSH server as the Git Repository. That way Git Repo will be located in only One Location and therefore we can efficiently use it as real Git Server.

All you have to do is create bare repository in the SSH server and clone in your local machine with the command:

$ git remote add origin ssh://user@host:1234/srv/git/example
This could be little different in MAC terminal though. In MAC terminal the URL will be different.
git remote add origin ssh://user@host/1234/srv/git/example
In SSH server:

  ~/documents $ mkdir test_repo.git
  ~/documents $ cd test_repo.git
  ~/documents/test_repo $ git init --bare
In Local Machine

  ~/documents $ mkdir source
  ~/documents $ cd source
  ~/documents/source $ git clone ssh://username@host:~/documents/test_repo.git







Wednesday, January 7, 2015

Up / Home Button in Android did not work?

Recently I had been developing an android app. At the final stage, I had the situation that the Up/Home button did not work.

I was sure, it was working at initial stages. Fortunately because of version control, I could track down the problem, and it turned out to be very very simple one.


Obviously I googled for the problem, and the very common suggestion was assigning android:parentActivityName in AndroidManifest.xml as explained in HERE. But this was not my problem, I had done exactly as it says.

I also had another solution. The solution was manipulating the function onOptionsItemSelected


@Override
public boolean onOptionsItemSelected(MenuItem item) { 
        switch (item.getItemId()) {
        case android.R.id.home: 
            onBackPressed();
            return true;
        }

    return super.onOptionsItemSelected(item);
}

However this seem to be rather hack. Because I know somewhere it is mentioned that: 
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
And because I had mentioned the parent activity properly, I expected it to work properly.

SO WHAT WAS THE MISTAKE I DID?

Well my mistake turned out to be, I placed
return true;
in onOptionsItemSelected


So the solution was to use:


return false
OR
return super.onOptionsItemSelected(item);