How to use Git

From Computational Biophysics and Materials Science Group
Jump to: navigation, search

Our server is also a Git server, it will be useful if you want to better manage your code or collaborate with others.

What is Git?

I got a very briefing introduction on Git video of 3 minutes. Take a look at it if you have interest.

Install git on your computer

GUI

There are many GUI clients for git, what I recommend is SmartGit, it is with non-commercial version that you can use for free.

Command Line Client

Just install git on your computer, go to Git - Installing Git to see how to do it.

Use Git

Create a Git Repository

To create a repository, you can choose to create one in your own home directory or common directory depending on whether you want to enable collaboration. I have create a folder "/share/apps/collaborate/" for every user where they can initialise a git then other could make changes to it. Create a git repository is very easy, go to the folder you want to create, for example:

cd /share/apps/collaborate/project_name/
git init --bare project_name.git

then finished. Details check here

Clone a Git Repository

Also very easy, on your own computer, navigate to the folder you want to clone to, for example:

cd ~/.../project_name/
git clone username@ourphysics.org:/share/apps/collaborate/project_name/project_name.git

then finished. Details check here If you are using GUI client, things become much more easier, check its user guide for help.

Commit Changes to a Git Repository

git commit -m "Commit Summary" -a

This will commit all changes with a summary "Commit Summary"

git commit -m "Commit Summary" some-file

This will only commit some-file with summary "Commit Summary" Details check here

Push Commits to a Git Repository

git push

This will push all commits to the default branch of the current repository to server. Details check here

Pull Commits from a Git Repository

Opposite to Push, pull pulls the commits from server.

git pull

Details check here

Git Cheatsheet

here