Skip to content

About

A quick-reference guide to essential Git commands for version control

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‡¬πŸ‡§ English | πŸ‡«πŸ‡· FranΓ§ais

πŸ“‹ Git Cheat Sheet

πŸŒ€ Git - Distributed Version Control System

🌐 GitHub - Git repository hosting service

πŸ› οΈ Basic Git Commands

git --version      # show Git version
git --help         # show help for Git commands

βš™οΈ Configure Git

git config --global user.name <name>     # set global username
git config --global user.email <email>   # set global email
git config --list                        # show Git configuration

Example:

git config --global user.name "Dmytro Palahin"
git config --global user.email "dmytro.palahin@gmail.com"

🏁 Initialize a Git repository

git init                                # initialize a Git repository in the project
git remote -v                           # show remote repositories
git remote add origin <repository-url>  # add a remote repository
git push -u origin master               # push changes to the remote repository

πŸ“Š Check repository status

git status                              # show staging area and changes to be committed

πŸ“œ View commit history

git log                                 # view history of commits

βž• Adding and Removing Files

git add .                               # add all files from working directory to the staging area
git add -f environment.yml              # add a specific file with force
git rm <file>                           # remove file from the staging area and working directory

πŸ’Ύ Commit Changes

git commit -m "<message>"               # commit changes in the staging area with a message

🌿 Check Out Branches and Commits

git checkout <commit hash>              # checkout a specific commit
git checkout <branch name>              # switch to an existing branch
git checkout -b <branch name>           # create a new branch and switch to it
git checkout main                       # switch back to the main branch

🌲 Branch Management

git branch <branch name>                # create a new branch
git branch                              # list all branches
git branch -a                           # list all branches, including remote ones
git branch -m <new name>                # rename the current branch
git branch -d <branch>                  # delete a branch (can't delete the current branch)
git branch -vv                          # list all branches with additional information

πŸ”€ Merging Branches

git merge <feature branch>              # merge a feature branch into the current branch
git merge -m "<message>" <branch>       # merge with a custom message

πŸ” Inspecting Commits

git cat-file -t <commit hash>           # show type of an object (commit, blob, etc.)
git cat-file -p <commit hash>           # show content of the object

πŸ”„ Push and Pull Changes

git push                                # push changes from the local repository to the remote
git pull                                # apply changes from a remote repository into your current local branch
git clone <url>                         # clone a remote repository to the local machine

🌐 Remote Repository Management

git remote add origin <url>             # connect a remote repository
git remote                              # list remote repositories
git remote -v                           # show URLs for remote repositories

πŸš€ Push Changes to Remote

git push -u origin <branch>             # push changes to the remote repository and track the branch
git push -u origin main                 # push changes to the main branch

πŸ”„ Typical Workflow

πŸ“Š Check the status of your working directory

git status

βž• Add or remove files

git add <file>              # add a specific file to the staging area
git rm <file>               # remove a specific file from the repository
git restore <file>          # undo changes in the working directory for a specific file

πŸ’Ύ Commit your changes

git commit -m "<message>"

πŸš€ Push changes to the remote

git push
git push --set-upstream origin <branch-name>

🌟 First-Time Setup for a New Remote Repository

🌐 Add the remote repository

git remote add origin <url>

βœ… Verify the remote is set correctly

git remote -v

🌿 Rename the current branch to main

git branch -M main

πŸš€ Push changes to the remote repository

git push -u origin main

🏷️ Adding and Managing Tags

πŸ“œ List Tags

git tag   # list all tags

🏷️ Create a Tag

git tag <tagname>                       # create a lightweight tag
git tag -a <tagname> -m "<message>"     # create an annotated tag with a message

πŸ” Show Tag Details

git show <tagname>                      # show details of a specific tag

πŸš€ Push Tags to Remote

git push origin <tagname>               # push a specific tag to the remote repository
git push origin --tags                  # push all tags to the remote repository

πŸ—‘οΈ Delete a Tag

git tag -d <tagname>                    # delete a specific tag
git push origin --delete <tagname>      # delete a tag from the remote repository

πŸ”„ Rename a Branch Locally and Remotely

🌿 Rename the branch locally

git branch -m <old-branch-name> <new-branch-name>

πŸš€ Push the renamed branch to the remote

git push origin <new-branch-name>

πŸ—‘οΈ Delete the old branch from the remote

git push origin --delete <old-branch-name>

🌐 Reset the upstream branch for the new branch

git push --set-upstream origin <new-branch-name>

🏷️ Rename a Tag Locally and Remotely

🏷️ Rename the tag locally

git tag <new-tag-name> <old-tag-name>       # create a new tag with the old tag's commit
git tag -d <old-tag-name>                   # delete the old tag locally

πŸš€ Push the new tag to the remote

git push origin <new-tag-name>

πŸ—‘οΈ Delete the old tag from the remote

git push origin --delete <old-tag-name>

About

A quick-reference guide to essential Git commands for version control

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors