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
You can clone repos or branches to any location to work on them.
I personally go over ssh which does not require a deamon to be setup.
It will use the same ssh port, nothing new required.
Here's a tutorial to get you started and some other helpful resources.
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:
git init --bare
Then locally, you can add the location of this new repo by adding a git "remote" to your local codebase:
git remote add origin ssh://myserver.com:/var/repos/my_repo.git
Now you have an "origin" server, which you can push to/pull from at will.
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:
sudo apt-get install git
There's an online Git Book and the git man pages, but here are some basics.
Make a folder "git-enabled":
git init
Add all of your current files in this folder to git's version control:
git add .
Commit these files to your local Git "staging area":
git commit -m "My first commit message"
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):
git push origin master
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:
git pull origin master
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:
git checkout -b new_branch
When you're done in new_branch
, checkout the master branch again and merge your changes:
git checkout master
git merge new_branch
If you want to see a diff of the two branches before merging, use the git diff
command:
git diff master new_branch
To see a log of all your commit, use git log
:
git log
Press 'q' to exit the log view.
In any given day, those are the commands I use most.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With