LinuxSysAdminsDoc/readme.md

222 lines
5.2 KiB
Markdown
Raw Normal View History

2021-04-01 12:11:34 +02:00
# Git
2021-04-01 14:31:18 +02:00
![GitHub Logo](img/image.jpg)
2021-04-01 12:11:34 +02:00
## Usefull links
[Git Cheat Sheet](https://education.github.com/git-cheat-sheet-education.pdf)
2021-04-01 13:47:50 +02:00
## Git System
2021-04-01 14:31:18 +02:00
![Git System](img/Git_Guide.png)
2021-04-01 14:21:34 +02:00
## Remote Execution
2021-04-01 14:31:18 +02:00
![Remote Execution](img/Remote_execution.png)
2021-04-01 13:47:50 +02:00
2021-04-02 10:48:01 +02:00
2021-04-01 12:11:34 +02:00
## Basic commands
=================
2021-04-01 12:11:34 +02:00
2021-04-01 14:21:34 +02:00
### Initialize an existing directory as a Git repository
2021-04-01 12:11:34 +02:00
```bash
$ git init
Initialized empty Git repository in C:/Users/Admin/Documents/Git/.git/
```
2021-04-01 14:21:34 +02:00
### Show modified files in working directory, staged for your next commit
2021-04-01 12:11:34 +02:00
```bash
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
Readme.md
image.jpg
nothing added to commit but untracked files present (use "git add" to track)
```
2021-04-01 14:21:34 +02:00
### Add a file as it looks now to your next commit (stage)
2021-04-01 12:21:55 +02:00
```bash
$ git add Readme.md image.jpg
```
2021-04-01 14:21:34 +02:00
### Commit your staged content as a new commit snapshot
2021-04-01 12:21:55 +02:00
```bash
$ git commit -m "First Commit"
[master (root-commit) 784ae2e] First Commit
Committer: unknown <Admin@FOR209-03.irisib.lan>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
2 files changed, 61 insertions(+)
create mode 100644 Readme.md
create mode 100644 image.jpg
```
2021-04-01 14:21:34 +02:00
### Set a name & email that is identifiable for credit when review version history
2021-04-01 12:21:55 +02:00
```bash
$ git config --global user.name “[firstname lastname]”
$ git config --global user.email “[valid-email]”
```
2021-04-01 14:21:34 +02:00
### Show all commits in the current branchs history
2021-04-01 12:21:55 +02:00
```bash
$ git log
commit 784ae2e2d10720c23eb7cebdf8386ef2157fe628 (HEAD -> master)
Author: unknown <Admin@FOR209-03.irisib.lan>
Date: Thu Apr 1 12:11:34 2021 +0200
First Commit
```
### tig vs git log --graph
Tig allows you to browse changes in a Git repository and can additionally act as a pager for output of various Git commands. When used as a pager, it will display input from stdin and colorize it.
When browsing repositories, Tig uses the underlying Git commands to present the user with various views, such as summarized commit log and showing the commit with the log message, diffstat, and the diff.
2021-04-02 15:48:59 +02:00
> $ tig
## tig
![tig](img/tig.PNG)
2021-04-02 15:48:59 +02:00
> $ git log --graph
## git log
![git log](img/git_log.PNG)
2021-04-02 10:48:01 +02:00
## SHARE & UPDATE
### Retrieving updates from another repository and updating local repos
=================================
add a git URL as an alias
>git remote add [alias] [url]
fetch down all the branches from that Git remote
>git fetch [alias]
merge a remote branch into your current branch to bring it up to date
>git merge [alias]/[branch]
Transmit local branch commits to the remote repository branch
>git push [alias] [branch]
>git pull
fetch and merge any commits from the tracking remote branch
## BRANCH & MERGE
### Isolating work in branches, changing context, and integrating changes
![Remote Execution](img/Branching.png)
>git branch
list your branches. a * will appear next to the currently active branch
>git branch [branch-name]
create a new branch at the current commit
>git checkout
switch to another branch and check it out into your working directory
>git checkout -b|-B <new_branch> [<start point>]
Specifying -b causes a new branch to be created as if git-branch(1) were called and then checked out.
If -B is given, <new_branch> is created if it doesnt exist; otherwise, it is reset. This is the transactional equivalent of
>git merge [branch]
merge the specified branchs history into the current one
>git log
show all commits in the current branchs history
## TRACKING PATH CHANGES
### Versioning file removes and path changes
=================================
Delete the file from project and stage the removal for commit
>git rm [file]
Change an existing file path and stage the move
>git mv [existing-path] [new-path]
Show all commit logs with indication of any paths that moved
>git log --stat -M
2021-04-01 13:40:03 +02:00
### History
2021-04-01 14:21:34 +02:00
```bash
2021-04-01 13:40:03 +02:00
history
1 git init
2 git status
3 git add Readme.md image.jpg
4 git status
5 git commit -m "First Commit"
6 git config --global user.name vl4dd
7 git config --global user.email ticus@kraland.net
8 git commit -m "First Commit"
9 git status
10 git log
11 git commit -m "Second commit"
12 git add Readme.md
13 git commit -m "Second commit"
14 git log
2021-04-01 14:21:34 +02:00
```
2021-04-01 12:11:34 +02:00
2021-04-01 15:26:20 +02:00
###
2021-04-01 12:11:34 +02:00
Checker le satus
> git status
Ajouter un element dans la branche
> git add Readme.md
Commit les changement
> git commit -m "First commit"
Show all commit
>git checkout
Merge
>git merge
## Setup
### Configuring user information used across all local repositories
>git config --global user.name “[firstname lastname]”
set a name that is identifiable for credit when review version history
>git config --global user.email “[valid-email]”
set an email address that will be associated with each history marker
>git config --global color.ui auto
2021-04-02 11:47:09 +02:00
set automatic command line coloring for Git for easy reviewing
Je test sarahrm95