Git

De Wiki de Calcul Québec
Aller à : Navigation, rechercher
Cette page est une traduction de la page Git et la traduction est complétée à 100 % et à jour.

Autres langues :anglais 100% • ‎français 100%

Sommaire

Description

Git is a distributed, fast and secure source code manager (SCM). The official Git website is gitscm.org. The Git software has initially been created by Linus Torvalds for the Linux project. The current maintainer is now Junio Hamano. The development of Git itself is performed on the kernel.org plateform.

Operating Principle

Contrary to CVS and SVN managers, and similarly to Mercurial, Git works in a distributed way. This means that developpers do not depend on a central repository to commit their changes. Each Git repository contains the full history of the project. Each Git object (changeset, file, directory) is a leaf of a tree with multiple branches. Developping a project with Git is based on a model in which one branch corresponds to one feature. Many revisions of the feature may be archived before the branch gets merged with the main trunk. For a detailed explanation of branch development, we recommend reading this page.

One especially interesting technique is cherry-picking, which is essentially taking part of a branch and merging it to another one. This page describes how to use this technique with Git.

Basic usage

Generally, a project developper must be able to:

  1. clone or create the repository;
  2. make changes;
  3. commit changes;
  4. push changes toward the original repository.

Since Git is distributed, there may not be an authoritative repository.

Summary of commands

Basic commands
Command Description
git config Configures git
git init Creates a new repository
git clone Clones an existing repository
git add Adds a file or directory to a repository
git rm Deletes a file or directory from the repository
git commit Commits changes to the repository
git push Pushes commited changes to a different repository
git pull Pulls changes from a different repository and merges them with your own repository
git fetch Fetches changes from a different repository without merging them to yours
git merge Merges changes to the repository


Commands to explore changes
Command Description
git blame Gives the origin of each change
git log Displays changes history
git diff Compares two versions
git status Displays status of the current files
git show Displays various git objects
git cat-file Displays the content, type or size of objects


Commands for branches, tags and remote repositories
Command Description
git branch Manages development branches
git tag Manages version tags
git remote Manages remote repositories
git checkout Checks out a branch or a path
git reset Changes the head of a branch


Commands for patches
Command Description
git format-patch Creates a patch
git am Applies a patch
git send-email Sends a patch by email


Other commands
Command Description
git bisect Used to diagnose problems
git gc Collects garbage objects
git rebase Rebases history of the repository
git grep Searches for content

Creating or cloning a repository

The first step usually is to create your own repository, or to clone an existing one.

To create a repository:

[name@server $]  git init my-project


To clone a repository:

[name@server $]  git clone git://github.com/git/git.git


Commiting a change

When the repository is ready, you change directory and edit the file

 
 [name@server $] cd my-project
 [name@server $] nano file.txt
 


When work is done, you add the file:

[name@server $]  git add file.txt


and commit the change

[name@server $]  git commit


It is then possible to push changes to the origin repository with:

[name@server $]  git push origin master


In the above command, origin is the remote repository and master is the current branch that will be pushed.

Hosting Git repositories

GitHub and Bitbucket are two of the main Git repository hosting services. They are both available for commercial projects as well as free projects.

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Ressources de Calcul Québec
Outils
Partager