Skip to content

Instantly share code, notes, and snippets.

@Max-im
Last active June 15, 2023 15:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Max-im/2d75ea60b5df48a74e13b4f4cb697470 to your computer and use it in GitHub Desktop.
Common commands for git

Git Cheat Sheet

Common

Instalation

git init

add all changing in git

git add .

create commit

git commit -m 'text'

change the last commit (WE CAN CHANGE ONLY THE LAST COMMIT)

git commit --amend -m "text"

Info

view commits info

git log
git log --since="2 weeks ago" --until="3 days ago"
git log --graph
git log --online --graph --all --decorate

status of the current files state

git status

current diff from the last commit (added/ removed files info)

git diff

different between current state and the last commit

git --diff --cached (different between current state and buffer)
git --diff <commitId> <path>
git --diff <commitId>..<commitId>

print source tree and commitsId

git ls-tree master <path or blank>

HEAD

cancel "add" command for file

git reset HEAD <fileName.js>

return current state to the last commit IF THEY ARE NOT COMMITED and NOT ADDED

git checkout -- <fileName.js>

make <fileName.js> in state

git checkout <commitId> -- <fileName.js>

Reset

create new commit, cancaling prev commit

git revert

switch HEAD to

git reset --soft <commitId>

(default mixed) switch HEAD to and all state

git reset <commitId>

switch HEAD to and remove all next commits and state

git reset --hard <commitId>

Branch

show all branches

git branch

create new branch

git branch <branchName>

checkout // git checkout -b

git checkout <branchName>

rename branch

git branch -m <oldName> <newName>

remove branch

git branch -d <branchName>
git branch -D <branchName>

merge branches // git merge --no-ff

git checkout <branchNameMainTO>
git merge <branchNameSlaveFrom>

abort merging

git merge --abort

Remote

show all remote severs

git remote

create new remote

git remote add <alias> <url>

remove remote

git remote rm <alias>

push branch on remote

git push -u <align> <branchName>

clone 1 branch from remote // git clone -b []

git clone <url> [<path>]

fetch remote info // NEEDS MERGE git merget origin/master

git fetch <alias>

git fetch + git merge

git pull 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment