Skip to content

WishEdu/git-commands-cheatsheet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Git


Commands

git config --global user.name "name" - setup users name in global config

git config --global user.email <email> - setup users email in global config

git init - initialization git in project

git status - status local files

git log - show log of all commits

  • git log --oneline - short log

  • git log --graph --oneline - short log with drawled graph

git diff <(commit-id/branch)-from> <(commit-id/branch)-to> - show log difference in commits

  • git diff --staged - show log difference in commits

git branch <branch-name> - create branch

  • git branch -v - info about last commit

  • git branch -M <branch-name> - rename current branch

  • git branch -d <branch-name> - deletes this branch

git checkout <branch-name/commit-id> - change current (HEAD) branch or change current commit

  • git checkout -b <branch-name> - create and change current (HEAD) branch

git add <file1> <file2> - add files for git indexing

git commit - add commit

  • git commit -m "message" - add commit changes with message

  • git commit -am "message" - add commit all last changes with message

  • git commit --amend -m "new message" - rename last changes commit

  • git commit --amend --no-edit - expand last commit with new files

  • git commit --amend -c <commit-id> - rename commit by id

git remote add origin <url> - connect to first time created repo

  • git remote add pb <url> - connect to already exist repo

  • git remote -v - log connected remotes

git stash - archive last changes, which not committed (unfinished changes)

  • git stash pop - get archive changes

git reset <commit-id> - return to commit-id

  • git reset --hard - return to one commit back

git restore <file> - restore non staged file

  • git restore --staged <file> - restore staged file

git revert <commit-id> - reverts that commit with a new commit

git push - upload last changes

  • git push -u origin <branch-name> - upload branch

git pull - download last changes

  • git pull --rebase origin <branch> - pull with with rebase option (if have conflicts with origin branch)

git merge <branch> - merge in current brunch

  • git merge --no-edit <branch> - merge without message edit

git rebase <branch> - rebase (overlay) commits from one branch to current or other

  • git rebase --abort - cancel rebase

  • git rebase --continue - fix conflicts

The sequence of actions when connecting to the working repository

  1. git init

  2. git add .

  3. git commit -m "Init"

  4. git branch -M main

  5. git remote add origin <url>

  6. git push -u origin main

The sequence of actions when connecting to already existing repository

  1. git clone <url>

  2. cd <cloned-repo-folder>

  3. git remote add pb <url>

  1. git rm -r --cached

  2. git add .

  3. git commit -m "Untrack files in .gitignore"

Some abbreviations

origin - remote branch

-f or --force - force action

--staged - staged (prepared with add command) files

~ - parent / home

@ - HEAD - last commit

* or . - all; *may not find files whose names begin with . (like .env)

About

Basic git commands with description

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Markdown 100.0%