Хватит гуглить каждую мелочь — держи ультимативную шпаргалку ровно на 41 команду Git. Только хардкор и рабочие конструкции для консоли.
1. Создание репозитория и сохранение изменений# Клонировать существующий репозиторий (Clone an existing repository)
$ git clone [url]
# Инициализировать новый проект (Initialize new version-controlled project)
$ git init
# Сохранить изменения в репозиторий (Save changes to the repository)
$ git add .
$ git commit -m "first commit"
# Текущее состояние репозитория (Current state of the repository)
$ git status
2. Управление ветками# Создать новую ветку (Create a new branch)
$ git branch [branchName]
# Показать все локальные и удаленные ветки (List all remote or local branches)
$ git branch -a
# Удалить ветку (Delete a branch)
$ git branch -d [branchName]
# Слить изменения в текущую ветку (Merge changes into current branch)
$ git merge [branchName]
# Переключиться на существующую ветку (Checkout an existing branch)
$ git checkout [branchName]
$ git switch [branchName]
# Переключиться и создать новую ветку (Checkout and create a new branch with that name)
$ git checkout -b [newBranch]
$ git switch -c [newBranch]
3. Теги, синхронизация и удаленные репозитории# Создать тег (Create a tag)
$ git tag [tagName]
# Удалить тег (Delete the tag)
$ git tag -d [tagName]
# Отправить теги (Push tags)
$ git push --tags
# Получить последнюю версию репозитория (Get the latest version of a repository)
$ git pull [branchName] [remoteURL/remoteName]
# Добавить удаленный репозиторий (Add remote repository)
$ git remote add [remoteName] [remoteURL]
# Отправить локальные коммиты в удаленный репозиторий (Send local commits to the remote repository)
$ git push [remoteURL/remoteName] [branch]
# Показать URL удаленных репозиториев (Show remote URLs)
$ git remote -v
4. Отмена действий и удаление файлов# Отменить предыдущий коммит (Undo the previous commit)
$ git revert HEAD^
# Забыть о файлах, которые отслеживались, но теперь в .gitignore (Forget about files that were tracked but are now in .gitignore)
$ git rm -r --cached .
$ git add .
$ git commit -am "remove ignored files"
# Удалить файл из рабочего индекса (Remove a file from the working index (cached))
$ git rm --cached [fileName]
# Удалить файл принудительно (Delete a file (force))
$ git rm -f [fileName]
# Удалить всю директорию из рабочего индекса (Remove an entire directory from the working index (cached))
$ git rm -r --cached [directoryName]
# Удалить всю директорию принудительно (Delete an entire directory (force))
$ git rm -r -f [directoryName]
# Удалить удаленную ветку (Delete a remote branch)
$ git push origin :[branchName]
5. Прятанье изменений (Stash) и базовые настройки# Спрятать текущую работу с неотслеживаемыми файлами (Store current work with untracked files)
$ git stash -u
# Вернуть спрятанную работу обратно в рабочую директорию (Bring stashed work back to the working directory)
$ git stash pop
# Задать имя автора для всех коммитов (Define the author name to be used for all commits)
$ git config --global user.name [name]
# Задать email автора для всех коммитов (Define the author email to be used for all commits)
$ git config --global user.email [email]
# Полезные руководства, поставляемые с Git (Helpful guides that come with Git)
$ git help -g
6. История, изменения и сложные переносы# Показать лог коммитов (Show commit log)
$ git log
$ git log --oneline
# Показать изменения (Show changes)
$ git diff
# Изменить сообщение последнего коммита (Amend last commit message)
$ git commit --amend
# Посмотреть, кто менял файл (Blame a file)
$ git blame [fileName]
# Перенести конкретный коммит (Cherry-pick a commit)
$ git cherry-pick [commitHash]
# Выполнить rebase на другую ветку (Rebase onto another branch)
$ git rebase [branchName]
❗️❗️❗️ Нравится формат? Ставь 👍
👉 Рубрика: #шпаргалка@LinuxSkill
⭐️ Зеркало в MAX
#Linux #Git #DevOps #Sysadmin #CLI #Bash