Connect to git without a password

Add the following in ~/.ssh/config:

Host git.droidzone.in
     Hostname git.droidzone.in
     User git
     IdentityFile ~/.ssh/id_rsa_mypvtkey

Note that the “Host” line is important, and cannot be just about any string (for git. For ssh it didnt matter). I found that git would ask me for a password if the Host line was something other than the actual hostname, even if the “Hostname” line was correct.

So, Host and Hostname should be the server address (name or IP)

If the ‘config’ file contains the proper lines, ssh-add isnt required.

Now add the key to ssh:

ssh-add ~/.ssh/id_rsa_mypvtkey

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Git on bitbucket always asks for password

I noticed that even after adding my public ssh key to Bitbucket, it asks for my password, and dies with an “fatal: Authentication failed”, if I dont give it the password. Obviously typing out the password is tedious, esp if you have a 40 letter complex password. 🙂

Reason:

You cloned the repo using https:// link instead git@ link.

Solution:

Change your remote URL: Error message:

#git push origin master
Password:
fatal: Authentication failed

You can first check if this is the case, by listing out your remotes, with:

#git remote -v
origin  https:[email protected]/droidzone/securessh.git (fetch)
origin  https:[email protected]/droidzone/securessh.git (push)

Now, change the remote for “origin”, with:

#git remote set-url origin [email protected]:droidzone/securessh.git

Now, try again:

#git push
Warning: Permanently added the RSA host key for IP address '' to the list of known hosts.
Everything up-to-date

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Upgrading Roundcube on iredmail to latest git master

cd /tmp
git clone https://github.com/roundcube/roundcubemail.git
cd roundcubemail
./bin/installto.sh /usr/share/apache2/roundcubemail-0.8.6
service apache2 restart

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Change default git commit message editor

To change the default commit message editor to emacs, type the following in bash:

git config --global core.editor "emacs"

where you can write the name of your editor in place of emacs


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Easier .gitignore file generation

You know when you start off building a kernel after creating a default .gitignore file containg list of object files and other temp files to be ignored, and at the end of a compilation, when you run a “git status”, you get a long list of new files that arent necessary to be included in the git. Manually adding them without wildcards is a headache. If you do add them with wildcards, you may potentially have conflicts with essential source scripts.

In this case, you can use the list output by git to your advantage.

You can just pipe the “git status” output to a file, and use it to add to your .gitignore.

Eg:

git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   .gitignore
#       modified:   include/config/kernel.release
#       modified:   include/generated/compile.h
#       modified:   include/generated/utsrelease.h
#       modified:   scripts/basic/fixdep
#       modified:   scripts/conmakehash
#       modified:   scripts/kallsyms
#       modified:   scripts/kconfig/conf
#       modified:   scripts/mod/elfconfig.h
#       modified:   scripts/mod/mk_elfconfig
#       modified:   scripts/mod/modpost
#       modified:   scripts/recordmcount
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       ..tmp_vmlinux1.cmd
#       ..tmp_vmlinux2.cmd
#       .missing-syscalls.d
#       .tmp_System.map
#       .tmp_kallsyms1.S
#       .tmp_kallsyms2.S
#       .tmp_versions/
#       .tmp_vmlinux1
#       .tmp_vmlinux2
#       .vmlinux.cmd
#       System.map
#       arch/arm/boot/.Image.cmd
#       arch/arm/boot/.zImage.cmd
#       arch/arm/boot/compressed/.piggy.lzma.cmd
#       arch/arm/boot/compressed/.vmlinux.cmd
#       arch/arm/boot/compressed/lib1funcs.S
#       arch/arm/boot/compressed/piggy.lzma
#       arch/arm/boot/compressed/vmlinux.lds
#       arch/arm/common/modules.builtin

Capture it to a file pipe.

git status > ../unnecessary.txt
cat ../unnecessary.txt | awk '{for(i=3;i<=NF;++i)print $i}'

 

 

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Git – Reset to particular commit

List all commits from history, and choose the required commit.

[[email protected] kernel]$git log --pretty=oneline
8983d7058d2f6b7ff907328c53fc0e97d5c0f576 ^
832219061059f8d9af922a54bb935927c5bbedff New
b53e4b1de439e031bd50fe9aa4fd84dd51e2e438 Added missing
02086fc547c3ffbba4abf07327bb18cda3dfee0f Missing files
d6f61dadd035ef118231b4144ffcc05c6282212b More missing files added
ed26cc3c8c4709ad53bd9365394e6f40352f0461 Added files missed by buggy .gitignore rules
5ce7674d493bc1401f6aa45d3e817a839f3a21c5 Added some missing files
cd2cebfe9f70c07b00650faa21d28f9d6c50516a .Gitignore changes
d5c8c3f188672a5a1f8c8d5c959f0fe280e827c1 Toolchain location change
0ee33d2545676c5f38719ae0b1ccf539d987ac49 Merge branch 'master' of ssh://bitbucket.org/droidzone/kernel_android_n7100_v1
8b34f1deaaa4305ba31388946de098a784efc7d6 Android README info A few more .gitignore files
df5f8a17a25a2240ad7baf2651a1df1a366b25b6 Android README info A few more .gitignore files
11aa64f2d0fff0cda4753db88072b0a0f34816f6 Compiler errors: Fixes for the following error:
b9202d534b4a342cfd6baf914ddbace25b4c94df Fix for compiler errors: Switched always_inline
ea1e1b5cb75bde723fbc033d13546c34f990378b Fix for inlining error during compilation
404c50fe3e735581754c47e0ebb24e7ea1c15902 Compiler fixes?
e52b83584f9316422b18b7166fcfdecf218ed715 Disable module versioning
c299ec681a2c2c98f649701d7cb612a160421e7b Toolchain customizationsy
e260d9fd0c998a545ea8134f9c416f89592c10d8 Makefile changes: Added toolchain customization (NDK) gcc 4.4.3 .config: defconfig +   [x] Bzip2, lzma, xz com
5b6dbfb958551a6f0f8bbeb4bb9856ea64afac5c First commit

I want to reset to first commit and clean up the history too (so that it will be as if the commits following from that commit will cease to have ever existed).

[[email protected] kernel]$git reset --hard 5b6dbfb958551a6f0f8bbeb4bb9856ea64afac5c

As you can note, here the SHA of the first commit is entered.

You can confirm that the git has been taken back to first commit:

[[email protected] kernel]$git log
commit 5b6dbfb958551a6f0f8bbeb4bb9856ea64afac5c
Author: droidzone &lt;[email protected]&gt;
Date:   Mon Dec 24 23:01:32 2012 +0530

    First commit

    Samsung Galaxy Note2 N7100
    --------------------------
    - Droidzone www.droidzone.in
    - Support/Downloads: www.note2.droidzone.in

    Initial Modifications:
    [x] Based on Samsung IN Source Drop - GT-N7100_JB_Opensource.zip
    [x] Added cypress resistive touch button drivers from GT-N7100_HK_JB_Opensource.zip
        Samsung Source: http://opensource.samsung.com/

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Git force overwrite of untracked local files during a pull

I made some changes to .gitignore so that untracked files were formed in the repo. When I tried a pull, it failed:

[[email protected]] ~/kernel/kernel_android_n7100_v1 $git pull origin
Updating df5f8a1..d6f61da
error: The following untracked working tree files would be overwritten by merge:
        include/config/accessory.h
        include/config/aeabi.h
        include/config/alignment/trap.h
        include/config/android.h

So the solution was to do a:

git fetch --all
git reset --hard origin/master
[[email protected]] ~/kernel/kernel_android_n7100_v1 $git fetch --all
Fetching origin
[[email protected]] ~/kernel/kernel_android_n7100_v1 $git reset --hard origin/master
HEAD is now at d6f61da More missing files added

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

A look into git merge conflicts

Here’s an example. I  made a couple of changes to my README file. These changes were done twice. In the first commit, I wrote the message that these were README changes. In the second edit, I made some formatting chnages to the README. Obviously I didnt want the kernel source to have two commits just for README. So I wanted to amend the last commit to take care of the new changes too and push to last commit.

So I tried that:

First push:

[[email protected] kernel_IN]$git commit -a
[master df5f8a1] Android README info A few more .gitignore files
 2 files changed, 32 insertions(+), 376 deletions(-)
 rewrite README (99%)
[[email protected] kernel_IN]$git push origin master
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 935 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: bb/acl: droidzone is allowed. accepted payload.
To ssh:[email protected]/droidzone/kernel_android_n7100_v1.git
   11aa64f..df5f8a1  master -&gt; master

Now I made the changes I wanted.

[[email protected] kernel_IN]$emacs README

Now changing the last commit message:

[[email protected] kernel_IN]$git commit --all --amend
[master 8b34f1d] Android README info A few more .gitignore files
 2 files changed, 32 insertions(+), 376 deletions(-)
 rewrite README (99%)

Now I try to push. I get a failed message because the same commit exists on remote and is different.

[[email protected] kernel_IN]$git push origin master
To ssh:[email protected]/droidzone/kernel_android_n7100_v1.git
 ! [rejected]        master -&gt; master (non-fast-forward)
error: failed to push some refs to 'ssh:[email protected]/droidzone/kernel_android_n7100_v1.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So it asked me to pull. I try that. Obviously there’s a conflict again.

[[email protected] kernel_IN]$git pull
Auto-merging README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.

Fine. So I need to merge the conflicts manually.

[[email protected] kernel_IN]$git mergetool
merge tool candidates: opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse ecmerge p4merge araxis bc3 emerge vimdiff
Merging:
README

Normal merge conflict for 'README':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (kdiff3):

Now it opened the nice GUI where I’m able to compare the three files and edit each one, then choose one of them.

I chose to use File B for all.

On closing the tool, this happened.

Next I have to commit afresh:

[[email protected] kernel_IN]$git commit -a
[master 0ee33d2] Merge branch 'master' of ssh://bitbucket.org/droidzone/kernel_android_n7100_v1

It automatically added the commit message as a merge conflict resolution commit.

Now I can push the changes.

[[email protected] kernel_IN]$git push
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 577 bytes, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: bb/acl: droidzone is allowed. accepted payload.
To ssh:[email protected]/droidzone/kernel_android_n7100_v1.git
   df5f8a1..0ee33d2  master -&gt; master

In the end I suppose it didnt really offer advantages to amend changes and then make this additional commit. I know I’m missing a git command.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Automating Git for passwordless logins- Setup git key pairs and setup ~/.ssh/config file

I’ve already posted about how to create key pairs fo SSH elsehere.

This is a short listing of the ~/.ssh/config file used for Git:

Host goob
     HostName buildbot1.snipanet.com
     User droidzone
     IdentityFile ~/.ssh/privatekey_goo
     ServerAliveInterval 30
     ServerAliveCountMax 120
Host goo
     HostName upload.goo.com
     User droidzone
     IdentityFile ~/.ssh/privatekey_goo
     ServerAliveInterval 120
     ServerAliveCountMax 120
     Port 2222
Host xda
     HostName build1.dev.xda-developers.com
     User droidzone
     IdentityFile ~/.ssh/xdamachine_key_openssh_pvt
     ServerAliveInterval 30
     ServerAliveCountMax 120
Host sf
     HostName shell.sourceforge.net
     User droidzone
     IdentityFile ~/.ssh/privatekey_sourceforge_ssh
     ServerAliveInterval 30
     ServerAliveCountMax 120
Host bitbucket.org
    IdentityFile ~/.ssh/id_rsa_bitbucket

 

Anatomy of a config file
A config file should be named ~/.ssh/config
The permissions of each key referred to by ssh should be restricted to user only, i.e chmod go=
The “Host” value is an alias
The “Hostname” value should be an ip or actual resolvable hostname
If Port is not 22, it should be specified in the file.

If the hostname is correct, you can login to sourceforge by typing: ssh sf
The username, hostname, key, port will be determined from the file.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Excluding a directory anywhere in the source tree from git

Just add the following line to your .gitignore file (the file should be located in the root of the git repo):

include/

Excludes all directories named include. Suppose I’m in /home/droidzone/kernel and there are subdirectories like the following:

/home/droidzone/kernel/include
/home/droidzone/kernel/arch/arm/include
/home/droidzone/kernel/exynos/include

The above rule will stop git from tracking all these directories.

In most cases the directory had already been tracked by the time you added the gitignore rule. In such an instance you can remove all these tracked directories from the git with the following:

git rm --cached -r include/

To be effective it should be combined with a .gitignore rule.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.