I use BitKeeper at work, and I would like to have a basic code backup for myself at home (considering I back up very rarely)
// I have never used git before so I need lots of help
I thought it might be a good idea to have a git repository on my home server, and then as I write code for school, work or personally I could simply clone branches from my home server work on them then push them back when I am done my work.
// Please correct me if this is not how git works, or how I should be doing this
I have installed git on my home server and would now like to know the best way to set it up, over ssh, git deamon ??
My server’s port for ssh is already forwarded must I add new ones for git?
And finally does this organization make sense to use git or is there a better product for me
Thanks
Git is great for version control and “backup” uses. If you want to access files from more than one computer, as you describe, the most pain-free way of getting a Git repository “up and running” is to use Github.com.
Github.com provides free space to host public Git repositories (it’s geared towards open source software). With a paid plan (starting $7/month), Git will give you space for completely private repositories, which only you (or people you allow) can access.
Otherwise, you can install Git yourself on your own server, in which case I’d recommend you setup SSH keys and access your repo over SSH (for ease of configuration and security). On your server, you can go into the folder you want to store your repo in and setup an “empty” repo like this:
Then locally, you can add the location of this new repo by adding a git “remote” to your local codebase:
Now you have an “origin” server, which you can push to/pull from at will.
Installing Git
If you’re on Windows, you should install msysgit and accept the defaults (I like to enable the option for Git to be added to my right-click context menu). I then use the Git Bash command-line utility to use Git, but it comes with a basic GUI tool as well.
If you’re on a Mac, you can download the Mac installer image and follow its instructions.
If you’re on Linux, you can use your package manager to install git. On the most recent version of Ubuntu, for example, you’d run:
Using Git
There’s an online Git Book and the git man pages, but here are some basics.
Make a folder “git-enabled”:
Add all of your current files in this folder to git’s version control:
Commit these files to your local Git “staging area”:
When you’re ready, you can push this local staging area to a remote repo, like github or your own server (assumes you already have a remote called “origin” setup, see above):
Which pushes the default “master” branch out to your remote repo. If you need to update your local copy with files from your remote repo’s master branch, do a “pull” instead:
Whenever you do new work, you want to create a branch and work there, so you don’t muddle the master branch, and so you can merge your changes once you know they’re working. So…
To create a new branch and start working in it, you can “checkout” the branch and create it simultaneously with the following:
When you’re done in
new_branch, checkout the master branch again and merge your changes:If you want to see a diff of the two branches before merging, use the
git diffcommand:To see a log of all your commit, use
git log:Press ‘q’ to exit the log view.
In any given day, those are the commands I use most.