Fork me on Github s

Posts Tagged git

Automatically keep your local git repos clean

Most developers using git are probably aware of a command ‘git gc’ that has to be run from time to time when you notice your git commands are running a little slow. This command cleans up your git repo and makes sure everything is nice and tidy. If you have not run this command lately, you will notice a huge performance increase in your git commands after running. It’s a bit annoying to have to run this command when you notice that your git performance is suffering. The command also takes a while if you have not run it recently. With this in mind, I decided to create a method to automatically run this command from time to time. So I decided to overload cd similar to how rvm does. All you have to do is paste the method in your .profile file and it will run the command every time you enter a directory with a git repo.

Here it is in all it’s glory.

Tags:

No Comments

Host your own private git repository via SSH

If you are like me you have tons of projects you would like to keep private but track with git, but do not want to pay a git host for a private plan. One of the problems is that most hosts scale their plans by project instead of users. Luckily, it is easy to host your own git repositories on any el cheapo host that provides ssh access.

In the interest of full disclosure, I learned this trick from this blog post. I decided to recreate it in case the source material vanishes for some reason.

To setup your host, login via ssh and run the following commands:

mkdir ~/git/yourprojectname.git
cd ~/git/yourprojectname.git
git --bare init

Then in your project directory (on your local machine):

# setup your user info
git config --global user.name "Firstname Lastname"
git config --global user.email "your_email@youremail.com"

# initialize the workspace
git init
git add .
git commit -m "initial commit"
git remote add origin ssh://youruser@yourhost.com/~/git/yourprojectname.git
git push origin master

It’s that easy!

To keep from entering your password every time add your public key to the server:

Generate your key with ‘ssh-keygen -t rsa‘ on your local machine. ┬áThen add the contents of the generated file to ~/.ssh/authorized_keys on your server.

Tags: ,

4 Comments

Git cheatsheet

Bookmark this sweet visual aid for git. Nicely done!

git cheatsheet

 

Tags: ,

No Comments