Git – setting up a remote repository and doing an initial “push”

There is a great deal of documentation and many posts on Git out there, so this is more of a note for myself as I keep forgetting the steps needed to set up a remote repository and doing an initial “push”.

So, firstly setup the remote repository:

ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
git-update-server-info # If planning to serve via HTTP
exit

On local machine:

cd my_project
git init
git add *
git commit -m "My initial commit message"
git remote add origin git@example.com:my_project.git
git push -u origin master

Done!

Team members can now clone and track the remote repository using the following:

git clone git@example.com:my_project.git
cd my_project

Bonus

To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile:

function parse_git_branch_and_add_brackets {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
}
PS1="\h:\W \u\[33[0;32m\]\$(parse_git_branch_and_add_brackets) \[33[0m\]\$ "

If You made a mistake and want to edit remote origin address just vim .git/config and You are all done.

Aside

Centos 6 – Adding EPEL repository

wget http://ftp.ps.pl/pub/Linux/fedora-epel/RPM-GPG-KEY-EPEL-6
rpm --import RPM-GPG-KEY-EPEL-6
rm -f RPM-GPG-KEY-EPEL-6

Now create /etc/yum.repos.d/EPEL.repo and paste:

[epel]
name=EPEL RPM Repository for Red Hat Enterprise Linux
baseurl=http://ftp.ps.pl/pub/Linux/fedora-epel/$releasever/$basearch/
gpgcheck=1
enabled=0

Now when You want to use repository You just do it like this:

yum --enablerepo=epel install [pakage]
Aside

MySQL high CPU usage

Recently my servers CPU gone wild. After running a top command MySQL was using up to 80% of CPU while mytop was showing no connections.

It turned out that the problem was ntp service and a leap second which was added to UTC time to compensate for the slowing rotation of the Earth.

The same problem I had with ruby on local development server.

Solution:

service ntpd stop
date -s "`date`"
service ntpd start

OS X: SSH tunnel in OS X Lion

Best and easiest way to secure your internet connection in untrusted network (like free Wi-Fi hotpot)?
SSH Tunnel :)

You’ll just need a shell account on a server and You’re ready to go. Fire up Terminal:

ssh -D 8080 -f -C -q -N user@yourserver.com

Legend:
-D 8080 : This basically does a lot of dynamic stuff and makes it behave as a SOCKS server. Of course you could use any non privileged port here (above 1023).
-f : This will fork the process into the background after you type your password.
-C : Turns on compression.
-q : Quiet mode. Since this is just a tunnel we can make it quiet.
-N : Tells it no commands will be sent. (the -f will complain if we don’t specify this).

Then open System Preferences -> Network.

Select active network connection, click Advanced... -> Proxies -> SOCKS Proxy.

In SOCKS Proxy Server enter localhost:8080 and You’re DONE! :)

Now You can check if Your IP Address changed in www.whatsmyip.org.

Aside

Quick Tip: Watch Me!

Very, very, very useful command!

Let’s say You want to observe the result of something being done every 5 seconds. For example list directory contents in which You’re creating backups in other thread. How to do this? Simply – use watch command:

watch -n5 'ls -lh /srv/backups'

Remember that brackets are very important and command in brackets can’t be alias (like ll for ls -l).

Mail.app: problem with IMAP synchronization

This problem occurred to me yesterday. Mail.app couldn’t synchronize with IMAP account properly. During investigation I’ve found out that it’s creating same one message in Drafts folder in a loop. After 1 day there was around 1300 messages… pretty cool, yeah? Nope, not really… Quick research and I’ve found a solution – remove Mail.app‘s offline cache. Fire up Terminal and do:

rm -rf /Users/$USER/Library/Mail/V2/[IMAP-account]/.OfflineCache

Mac OS X Lion 10.7.4

exFAT in Ubuntu 11.10

Why exFAT you are probably wondering. I have 5 different OS in my house: MediaPC is on Ubuntu 11.10, I’ve also got OSX Lion and Snow Leopard, Windows 7 and Vista. I was wondering what is the best FileSystem to work with all of them. For full support of NTFS under OSX I’ve only found paid solutions, FAT32 has it’s limitations (4GB max filesize)… after doing some research I’ve found that exFAT should be the one I’m looking for. It is natively supported by OSX and Windows (even XP!) the only thing was to make it work with my Ubuntu :) So here we go:

First we have to install fuse-ext:

sudo su -
add-apt-repository ppa:relan/exfat
apt-get update
apt-get install fuse-exfat

Now we are able to manualy mount exFAT-formatted drives. To make it automatical we’ll need to install couple more things:

apt-get install build-essential
apt-get install ncurses-dev
apt-get install util-linux

Everything should be working nicely now :)

Done on Ubuntu 11.10.32bit.