I have recently migrated my blog from Wordpress to Octopress during this migration I cloned a Git repository and setup my own, forcing me to learn some basic git commands.
Host your own Git repository (skip this if you are using Github)
Github offer free public repositories, however if you want a private repo you have have to pay $7 a month or host your own. I opted to host my own repo on CentOS, you can do the same with Mac OSX or even Winodws (I think), I chose to use my CentOS server as it’s accessable online so I can push pull my code from anywhere.
Enter the followinf as your user (not root) on your git server:
1 2 3 4 5
Make note of your git repo above, it’s required for the next step.
Make sure you are in your Git dir and enter the following on your local machine (note, you only need to rename origin if the repo you are working from was originally cloned):
1 2 3 4 5
I would recommend setting up SSH key based auth if you are not already using it, or you will have to enter your passphrase each time you push / pull with git.
How to use Git – basic Git commands
Now that we have the remote git repo setup, you can move to the next stage of the git tutorial and actually learn how to use git commands.
This guide assumes you have a some code in your local git dir and your remote repo is bare.
To push all your code to the remote repo you must first add the files & dir’s, cd into your code dir andenter the following to add all files & dir’s in the current directory:
You can now view the files & dir’s we just added with:
If you are happy that all the files & dir’s are correct you can then commit with:
Finally push your code with:
Your code should then be pushed the bare git repo we created at the start of the article.
Git Pull, How To pull code with git
How to pull code with git:
That’s all the commands you need to get started with git, for more functionality refer to the git man page with man git.