Git

From MEPIS Documentation Wiki

Jump to: navigation, search

Git is a distributed revision control system. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.

Contents

Installation

Git client is available through Synaptic. Or install it with this command

apt-get install git-core

Configuration

Set some useful global variables

 git config --global user.name "YourName"
 git config --global user.email "YourName@demo.com"

Set up a git repository

1. Depending on your purpose you can either clone locally a remote repo (downloading all the files to the local disk), for example, downloading the latest 2.6.x kernel

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

The git repository will be created in linux-2.6, you can cd to that directory:

cd linux-2.6

To re-sync (update) the local Git repo with the remote repo you can run this command (while in linux-2.6 directory):

git pull 

To push changes (if you have rights to publish on the remote repo) you can use this command:

git push

2. Another way to set a repository is to initializes a directory as a Git repository:

git init

Tracking changes

Once you cloned or initialized a Git repository you can start to edit file. Files are not tracked automatically by Git, to add files to "staging" area you need to use the add command:

git add filename 

(for specific file(s))
Or:

git add . 

(for all the files in the current directory and its sub-directories)

Once you reach a point where you are satisfied with the changes you can commit the changes with:

git commit -am "commit message" 

Common options: -a -- automatically stage all tracked, modified files before the commit (You still need to run git add to start tracking new files) -m -- adds a commit message

Branching

Branching is probably the most important feature of Git. You might want to create branches for multiple purposes: experimenting, create different branches for different features, keep copies of stable versions in different branches, branches for patches, etc.

You can create a branch with git branch branchname, switch into that context with git checkout branchname, record commit snapshots while in that context, then can switch back and forth easily. When you switch branches, Git replaces your working directory with the snapshot of the latest commit on that branch so you don't have to have multiple directories for multiple branches. You merge branches together with git merge branchname_to_be_merged.

Links

Personal tools