Setup

Set your name to be used as the commit author

git config --global user.name "Name Surname"

Set your email to be used as the commit author

git config --global user.email "your@email.com"


Creating Repositories

Initialize a new Git repository

git init

Clone an existing repository

git clone <repository>


Making Changes

Check the status of your repository

git status

Add a file to the staging area

git add <file>

Add all modified and new files to the staging area

git add .

Commit changes with a message

git commit -m "message"

Remove a file from the staging area

git reset HEAD <file>


Viewing History

View the commit history

git log

View changes that have not been staged

git diff

View changes that have been staged

git diff --staged


Working with Remotes

Add a remote repository

git remote add <name> <url>

Push changes to a remote repository

git push <name> <branch>

Pull changes from a remote repository

git pull <name> <branch>


Branching

List all branches

git branch

Create a new branch

git branch <name>

Delete a branch

git branch -d <name>

Switch to a branch

git checkout <name>


Merging

Merge a branch into the current branch

git merge <branch>

Stashing Changes

Stash changes

git stash

View a list of stashes

git stash list

Apply the latest stash

git stash apply

Discard the latest stash

git stash drop


Tagging

Create a new tag

git tag <tagname>

Create a new tag with a message

git tag -a <tagname> -m "message"

Delete a tag

git tag -d <tagname>

Push tags to the remote repository

git push --tags


Reverting Changes

Revert the last commit

git revert HEAD

Revert a specific commit

git revert <commit>


Resetting

Reset the staging area to the last commit

git reset HEAD

Reset the staging area and working directory to the last commit

git reset --hard HEAD

Reset the staging area and working directory to a specific commit

git reset --hard <commit>


Aliases

Create aliases for commonly used commands

git config --global alias.<alias_name> <git_command>
Vladimir Mikhalev
hey, I’m Vladimir Mikhalev, but my friends call me Valdemar. I have a lot of experience in the design and maintenance of various information systems.