Skip to content

GIT

Reminder of several command line about git tool.

About GIT

Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source-code management in software development, but it can be used to keep track of changes in any set of files. As a distributed revision-control system, it is aimed at speed, data integrity, and support for distributed, non-linear workflows.

Installation

# Debian/Ubuntu
apt install git

# Fedora or rpm based
dnf install git

# ArchLinux
pacman -S git

Configuration

System settings (For all users and repositories).

git config --system [settings] [value]

Settings for a specific user.

git config --global [settings] [value]

Configure specific repository.

git config [settings] [value]

Verify the setup file.

git config --list

Log

To see all history.

git log

Affect a structure to the log displaying with a display on one line.

git log --pretty=­one­line

We limit the numbers of logs displayed, we will display only last two logs.

git log -2

Local repository

We verify the files status.

git status

Verify the status within compact format.

git status -s

We index a new file or modified file.

git add [filen­ame]

Index all files of the working directory.

git add .

To see all modifications between the working directory and the index area (staged area) and in more we can see all modifications aren't in the index.

git diff

To see all modifications between the index area and the repository (the modifications who not have been yet commited).

git diff --changed

Save the modifications in the repository.

git commit
git commit -m "­[message]­"

Save all modifications in the repository without access to the index area.

git commit -a -m "­[message]­"

No longer index a file and delete it.

git rm [filen­ame]

No longer index a file without delete him.

git rm --cached [filen­ame]

Rename a file.

git mv [file_­from] [file_to]

Remote repository

List all names of remote repositories referenced locally.

git remote

List all remote repositories with their url.

git remote -v

Add and initialize a remote repository.

git remote add [short­name] [url]

Get all informations about a remote repository.

git fetch [short­name]

Get all informations about remote repositories.

git fetch --all

List informations from local repository about the status of local & remote branch.

git branch -vv

Get the data from remote repository and merge with local repository.

git pull

Send data to remote repository where the user have write rights.

git push [short­name] [branc­hname]

Inspect a remote repository.

git remote show [short­name]

Rename the shortname of remote repository.

git remote rename [current shortname] [new shortname]

Leave a remote repository.

git remote rm [shortname]

Back to the past

Remake a commit to change the message or tp add forgotten files.

git --amend

Delete one file from the index area.

git reset HEAD [filename]

Delete last commit from a file to come back at last modification.

git checkout -- [filename]

Tags

List all tags.

git tag

Use a filter to list all tags.

git tag -l [pattern]

Display the informations about a specific tag.

git show [tagname]

Create a tag with annotation.

git tag -a [tagname] -m "­[message]­"

Create a simple tag.

git tag [tagname]

Tag last commit of our choice.

git tag -a [tagname] [checksum commit]

Send a tag to a remote repository.

git push [short­name] [tagname]

Send all tag to a remote repository.

git push [short­name] --tags

Recover the files with specific tag and create a new branch whit this tag.

git checkout -b [branc­hname] [tagname]

Branch

List all branch.

git branch

List all branche merge with the current branch.

git branch --merged

List all branch not merged.

git branch --no-merged

Create a new branch.

git branch [branchname]

See where is the HEAD pointer.

git log --oneline --decorate

Changing branch.

git checkout [branchname]

Create a branch and go inside.

git checkout -b [branchname]

Merge several branch from our actual branch.

git merge [branc­hname]

Delete one branch.

git branch -d [branc­hname]

Delete one remote branch.

git push [short­name] --delete [branc­hname]