Git: Difference between revisions
(Marked this version for translation) |
No edit summary |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<languages /> | <languages /> | ||
[[Category:Software]] | |||
<translate> | <translate> | ||
== Description == <!--T:1--> | == Description == <!--T:1--> | ||
[https://en.wikipedia.org/wiki/Git Git] is a distributed, fast and secure source code management tool. The official Git website is [http://gitscm.org gitscm.org]. The Git software was initially created by [http://en.wikipedia.org/wiki/Linus_Torvalds Linus Torvalds] for the Linux project and the current maintainer is [http://en.wikipedia.org/wiki/Junio_Hamano Junio Hamano]. The development of Git itself is performed on the [https://git.wiki.kernel.org/index.php/Main_Page kernel.org] platform. | [https://en.wikipedia.org/wiki/Git Git] is a distributed, fast and secure source code management tool. The official Git website is [http://gitscm.org gitscm.org]. The Git software was initially created by [http://en.wikipedia.org/wiki/Linus_Torvalds Linus Torvalds] for the Linux project and the current maintainer is [http://en.wikipedia.org/wiki/Junio_Hamano Junio Hamano]. The development of Git itself is performed on the [https://git.wiki.kernel.org/index.php/Main_Page kernel.org] platform. | ||
== Operating | == Operating principle == <!--T:2--> | ||
Contrary to older source code management tools, Git works in a distributed way. This means that developers 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 the leaf of a tree with multiple branches. Developing 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 [http://nvie.com/posts/a-successful-git-branching-model/ this page]. | Contrary to older source code management tools, Git works in a distributed way. This means that developers 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 the leaf of a tree with multiple branches. Developing 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 [http://nvie.com/posts/a-successful-git-branching-model/ this page]. | ||
<!--T:3--> | <!--T:3--> | ||
One especially interesting technique is ''cherry-picking'', which is essentially taking part of a branch and merging it with another one | One especially interesting technique is ''cherry-picking'', which is essentially taking part of a branch and merging it with another one. | ||
== Basic usage == <!--T:4--> | == Basic usage == <!--T:4--> | ||
Line 146: | Line 147: | ||
== Creating or cloning a repository == <!--T:12--> | == Creating or cloning a repository == <!--T:12--> | ||
The first step usually | The first step is usually to create your own repository, or to clone an existing one. | ||
<!--T:13--> | <!--T:13--> | ||
Line 157: | Line 158: | ||
== Commiting a change == <!--T:15--> | == Commiting a change == <!--T:15--> | ||
When the repository is ready, you change directory and edit the file | When the repository is ready, you change directory and edit the file. | ||
{{Commands | {{Commands | ||
| cd my-project | | cd my-project | ||
Line 164: | Line 165: | ||
<!--T:16--> | <!--T:16--> | ||
When work is done, you add the file | When work is done, you add the file | ||
{{Command| git add file.txt}} | {{Command| git add file.txt}} | ||
and commit the change | and commit the change | ||
Line 170: | Line 171: | ||
<!--T:17--> | <!--T:17--> | ||
It is then possible to push changes to the origin repository with | It is then possible to push changes to the origin repository with | ||
{{Command| git push origin | {{Command| git push origin main}} | ||
<!--T:18--> | <!--T:18--> | ||
In the above command, ''origin'' is the remote repository and '' | In the above command, ''origin'' is the remote repository and ''main'' is the current branch that will be pushed. | ||
You might have to use <tt>git push origin master</tt> for older git repositories. | |||
== Hosting Git repositories == <!--T:19--> | == Hosting Git repositories == <!--T:19--> | ||
[http://github.com GitHub] and [http://bitbucket.org Bitbucket] are two of the main Git repository hosting services. They are both available for commercial projects as well as free projects. | [http://github.com GitHub] and [http://bitbucket.org Bitbucket] are two of the main Git repository hosting services. They are both available for commercial projects as well as free projects. | ||
</translate> | </translate> |
Latest revision as of 22:27, 8 July 2022
Description
Git is a distributed, fast and secure source code management tool. The official Git website is gitscm.org. The Git software was initially created by Linus Torvalds for the Linux project and the current maintainer is Junio Hamano. The development of Git itself is performed on the kernel.org platform.
Operating principle
Contrary to older source code management tools, Git works in a distributed way. This means that developers 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 the leaf of a tree with multiple branches. Developing 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 with another one.
Basic usage
Generally, a project developer must be able to:
- clone or create the repository;
- make changes;
- commit changes;
- push changes toward the original repository.
Since Git is distributed, there may not be an authoritative repository.
Summary of 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 |
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 |
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 |
Command | Description |
---|---|
git format-patch | Creates a patch |
git am | Applies a patch |
git send-email | Sends a patch by email |
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 is usually 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 main
In the above command, origin is the remote repository and main is the current branch that will be pushed.
You might have to use git push origin master for older git repositories.
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.