Основные команды Git для коммитов, веток, слияний, перебазирования, удалённых репозиториев и многое другое.
git config --global user.name "Name"Настройка & конфигурацияSet global author name
напр. git config --global user.name "Jane Doe"
git config --global user.email "email"Настройка & конфигурацияSet global author email
напр. git config --global user.email "[email protected]"
git config --listНастройка & конфигурацияList all configuration settings
git config --global core.editor "code"Настройка & конфигурацияSet VS Code as default editor
git config --global alias.<alias> <cmd>Настройка & конфигурацияCreate a command alias
напр. git config --global alias.st status
git initНастройка & конфигурацияInitialize a new local repository
git init <dir>Настройка & конфигурацияInitialize a repo in a specific directory
напр. git init my-project
git clone <url>Настройка & конфигурацияClone a remote repository
напр. git clone https://github.com/user/repo.git
git clone <url> <dir>Настройка & конфигурацияClone into a specific folder
напр. git clone https://github.com/user/repo.git my-dir
git statusИндексирование & основыShow working tree status
git status -sИндексирование & основыShort/compact status output
git add <file>Индексирование & основыStage a specific file
напр. git add README.md
git add .Индексирование & основыStage all changes in current directory
git add -pИндексирование & основыInteractively stage hunks of changes
git commit -m "msg"Индексирование & основыCommit staged changes with a message
напр. git commit -m "feat: add login page"
git commit -am "msg"Индексирование & основыStage tracked files and commit in one step
git commit --amendдеструктивноИндексирование & основыModify the most recent commit (message or content)
git diffИндексирование & основыShow unstaged changes
git diff --stagedИндексирование & основыShow staged changes (vs last commit)
git diff <branch1>..<branch2>Индексирование & основыCompare two branches
напр. git diff main..feature
git rm <file>Индексирование & основыRemove a file from working tree and index
напр. git rm old-file.txt
git rm --cached <file>Индексирование & основыUntrack a file without deleting it
напр. git rm --cached secret.txt
git mv <old> <new>Индексирование & основыMove or rename a tracked file
напр. git mv old.js new.js
git branchВетвление и слияниеList local branches
git branch -aВетвление и слияниеList all branches (local + remote)
git branch <name>Ветвление и слияниеCreate a new branch
напр. git branch feature/auth
git checkout <branch>Ветвление и слияниеSwitch to an existing branch
напр. git checkout main
git checkout -b <branch>Ветвление и слияниеCreate and switch to a new branch
напр. git checkout -b feature/auth
git switch <branch>Ветвление и слияниеSwitch branches (modern syntax)
напр. git switch main
git switch -c <branch>Ветвление и слияниеCreate and switch (modern syntax)
напр. git switch -c feature/auth
git branch -d <branch>Ветвление и слияниеDelete a merged branch
напр. git branch -d feature/auth
git branch -D <branch>деструктивноВетвление и слияниеForce delete a branch (unmerged too)
напр. git branch -D feature/old
git branch -m <old> <new>Ветвление и слияниеRename a branch
напр. git branch -m old-name new-name
git merge <branch>Ветвление и слияниеMerge a branch into current branch
напр. git merge feature/auth
git merge --no-ff <branch>Ветвление и слияниеMerge with a merge commit (no fast-forward)
git merge --squash <branch>Ветвление и слияниеSquash all commits from branch into one staged change
git merge --abortВетвление и слияниеAbort an in-progress merge
git remote -vУдалённые операцииList remote connections with URLs
git remote add <name> <url>Удалённые операцииAdd a new remote
напр. git remote add origin https://github.com/user/repo.git
git remote remove <name>Удалённые операцииRemove a remote connection
напр. git remote remove origin
git remote rename <old> <new>Удалённые операцииRename a remote
напр. git remote rename origin upstream
git fetchУдалённые операцииDownload all changes from remote (no merge)
git fetch <remote>Удалённые операцииFetch from a specific remote
напр. git fetch origin
git pullУдалённые операцииFetch and merge changes from remote
git pull --rebaseУдалённые операцииFetch and rebase onto remote branch
git push <remote> <branch>Удалённые операцииPush branch to remote
напр. git push origin main
git push -u origin <branch>Удалённые операцииPush and set upstream tracking
напр. git push -u origin feature/auth
git push --force-with-leaseдеструктивноУдалённые операцииSafe force push (fails if others pushed)
git push --tagsУдалённые операцииPush all tags to remote
git push origin --delete <branch>деструктивноУдалённые операцииDelete a remote branch
напр. git push origin --delete feature/old
git restore <file>деструктивноОтмена измененийDiscard changes in working directory
напр. git restore index.html
git restore --staged <file>Отмена измененийUnstage a file (keep changes)
напр. git restore --staged index.html
git reset HEAD <file>Отмена измененийUnstage a file (older syntax)
напр. git reset HEAD index.html
git reset --soft HEAD~1Отмена измененийUndo last commit, keep changes staged
git reset --mixed HEAD~1Отмена измененийUndo last commit, unstage changes (default)
git reset --hard HEAD~1деструктивноОтмена измененийUndo last commit, discard all changes
git reset --hard <commit>деструктивноОтмена измененийReset to a specific commit, discard everything after
git revert <commit>Отмена измененийCreate a new commit that undoes a specific commit
напр. git revert a1b2c3d
git revert HEADОтмена измененийRevert the most recent commit
git clean -fdдеструктивноОтмена измененийRemove untracked files and directories
git clean -nОтмена измененийDry run: show what would be cleaned
git stashПрипрятываниеStash current working directory changes
git stash push -m "msg"ПрипрятываниеStash with a descriptive message
напр. git stash push -m "WIP: auth feature"
git stash listПрипрятываниеList all stashes
git stash popПрипрятываниеApply most recent stash and remove it
git stash apply stash@{n}ПрипрятываниеApply a specific stash without removing
напр. git stash apply stash@{0}
git stash drop stash@{n}ПрипрятываниеDelete a specific stash
напр. git stash drop stash@{0}
git stash clearдеструктивноПрипрятываниеRemove all stashes
git stash branch <branch>ПрипрятываниеCreate a branch from a stash
напр. git stash branch feature/from-stash
git rebase <branch>Rebase & продвинутоеRebase current branch onto another
напр. git rebase main
git rebase -i HEAD~nRebase & продвинутоеInteractive rebase for last n commits
напр. git rebase -i HEAD~3
git rebase --continueRebase & продвинутоеContinue rebase after resolving conflicts
git rebase --abortRebase & продвинутоеAbort an in-progress rebase
git cherry-pick <commit>Rebase & продвинутоеApply a specific commit to current branch
напр. git cherry-pick a1b2c3d
git cherry-pick <c1>..<c2>Rebase & продвинутоеApply a range of commits
напр. git cherry-pick a1b2c3d..f6e5d4c
git bisect startRebase & продвинутоеStart binary search for a bug
git bisect good <commit>Rebase & продвинутоеMark a commit as good in bisect
git bisect bad <commit>Rebase & продвинутоеMark a commit as bad in bisect
git bisect resetRebase & продвинутоеEnd bisect session
git worktree add <path> <branch>Rebase & продвинутоеCheck out a branch into a separate directory
git logИнспекция & журналShow commit history
git log --onelineИнспекция & журналCompact one-line log
git log --oneline --graph --allИнспекция & журналVisual branch graph in terminal
git log -n <count>Инспекция & журналShow last N commits
напр. git log -n 5
git log --author="name"Инспекция & журналFilter commits by author
напр. git log --author="Jane Doe"
git log --since="2 weeks ago"Инспекция & журналShow commits since a date
git log -p <file>Инспекция & журналShow changes to a specific file over time
напр. git log -p README.md
git log --follow <file>Инспекция & журналFollow renames of a file in history
git show <commit>Инспекция & журналShow details of a specific commit
напр. git show a1b2c3d
git blame <file>Инспекция & журналShow who last modified each line
напр. git blame src/app.tsx
git shortlog -snИнспекция & журналSummarize commits by author
git reflogИнспекция & журналShow history of HEAD movements (recovery tool)
git grep "pattern"Инспекция & журналSearch working directory for a pattern
напр. git grep "TODO"
git tagТегиList all tags
git tag <name>ТегиCreate a lightweight tag
напр. git tag v1.0.0
git tag -a <name> -m "msg"ТегиCreate an annotated tag
напр. git tag -a v1.0.0 -m "Release v1.0.0"
git tag -a <name> <commit>ТегиTag a past commit
напр. git tag -a v0.9.0 a1b2c3d
git show <tag>ТегиShow tag metadata and commit
напр. git show v1.0.0
git push origin <tag>ТегиPush a specific tag to remote
напр. git push origin v1.0.0
git push origin --tagsТегиPush all tags to remote
git tag -d <tag>ТегиDelete a local tag
напр. git tag -d v1.0.0
git push origin --delete <tag>ТегиDelete a remote tag
напр. git push origin --delete v1.0.0
git merge объединяет две ветки, создавая коммит слияния и сохраняя полную историю обеих веток. git rebase перемещает коммиты с одной ветки на другую, переписывая историю для создания линейной, более чистой истории коммитов. Используйте merge для публичных веток и общей работы; rebase — для очистки локальных feature-веток перед слиянием.
Используйте git reset --soft HEAD~1, чтобы отменить последний коммит, сохранив изменения в индексе. Используйте git reset HEAD~1 (или --mixed) для удаления изменений из индекса, но сохранения их в рабочем каталоге. Используйте git reset --hard HEAD~1 для безвозвратного удаления коммита и всех изменений (деструктивная операция).
git fetch загружает изменения с удалённого репозитория, но НЕ объединяет их с вашей текущей веткой. Обновляет ваши удалённые отслеживающие ветки (origin/main). git pull — это git fetch + git merge (или git rebase с --rebase). Используйте fetch, если хотите проверить изменения перед их интеграцией.
После конфликтного слияния/rebase Git помечает конфликтующие файлы маркерами '<<<<<<', =======, >>>>>>. Откройте каждый конфликтующий файл, вручную выберите, какие изменения оставить, удалите маркеры, затем добавьте разрешённые файлы командой git add <файл> и завершите с git merge --continue или git commit.