Git commands
This repository is intended for all those who are new to Git and who want to know the basics
The main goal :
- Facilitate the handling of the Git tool
- Have a command base for documentation
๐ Notice
The [ ] show the type of content to add
๐ Git init
Command |
Description |
git init [repository name] |
Start a new repository. |
โ๏ธ Git clone
Command |
Description |
git clone [url] |
Obtain a repository from an existing URL. |
โ Git add
Command |
Description |
git add [file] |
Adds a file to the staging area. |
git add* |
Adds one or more file to the staging area. |
๐ฌ Git commit
Command |
Description |
git commit -m โ[ Type in the commit message]โ |
Records or snapshots the file permanently in the version history. |
git commit -a |
Commits any files youโve added with the git add command and also commits any files youโve changed since then. |
๐ Git diff
Command |
Description |
git diff |
Shows the file differences which are not yet staged. |
git diff --staged |
Shows the differences between the files in the staging area and the latest version present. |
git diff [first branch] [second branch] |
Shows the differences between the two branches mentioned. |
๐ Git reset
Command |
Description |
git reset [file] |
Unstages the file, but it preserves the file contents. |
git reset [commit] |
Undoes all the commits after the specified commit and preserves the changes locally. |
git reset --hard [commit] |
Discards all history and goes back to the specified commit. |
โ
Git status
Command |
Description |
git status |
Lists all the files that have to be committed. |
โ๏ธ Git rm
Command |
Description |
git rm [file] |
Deletes the file from your working directory and stages the deletion. |
๐ Git log
Command |
Description |
git log |
List the version history for the current branch. |
git log --follow [file] |
Lists version history for a file, including the renaming of files also. |
๐๏ธ Git show
Command |
Description |
git show [commit] |
Shows the metadata and content changes of the specified commit. |
๐ Git tag
Command |
Description |
git tag [commitID] |
Give tags to the specified commit. |
๐ฑ Git branch
Command |
Description |
git branch |
Lists all the local branches in the current repository. |
git branch [branch name] |
Creates a new branch. |
git branch -d [branch name] |
Deletes the feature branch. |
๐ต Git checkout
Command |
Description |
git checkout [branch name] |
Switch from one branch to another. |
git checkout -b [branch name] |
Creates a new branch and also switches to it. |
๐ Git merge
Command |
Description |
git merge [branch name] |
Merges the specified branchโs history into the current branch. |
๐๏ธ Git remote
Command |
Description |
git remote add [variable name] [Remote Server Link] |
Connect your local repository to the remote server. |
โฌ๏ธ Git push
Command |
Description |
git push [variable name] master |
Sends the committed changes of master branch to your remote repository. |
git push [variable name] [branch] |
Sends the branch commits to your remote repository. |
git push โall [variable name] |
Pushes all branches to your remote repository. |
git push [variable name] :[branch name] |
Deletes a branch on your remote repository. |
โฌ๏ธ Git pull
Command |
Description |
git pull [Repository Link] |
Fetches and merges changes on the remote server to your working directory. |
๐พ Git stash
Command |
Description |
git stash save |
Temporarily stores all the modified tracked files. |
git stash pop |
Restores the most recently stashed files. |
git stash list |
Lists all stashed changesets. |
git stash drop |
Discards the most recently stashed changeset. |