code

Cheat sheet for work with Git

Last updated: 26.10.2025
Views: 209

Git is an indispensable tool for managing versions of code in development. It allows you to track changes in the project, return to previous versions and work effectively in a team, preventing code conflicts. With its help, developers can conduct parallel work on different functions using branches, and then combine them. In addition, Git provides reliable storage of the history of changes, which helps to quickly find and correct errors. Due to its popularity, many services, such as GitHub and GitLab, offer convenient platforms for collaboration and project management. In this note, I collected the commands that I use in my work

The cheat sheet on version control system – Git

to see commits

git log --pretty=oneline

to see remote URL repositories

git remote -v

to clone into a non-empty directory

git init
git remote add origin https://name@bitbucket.org/name/rep.git
git fetch
git checkout -t origin/master

an event log

git reflog

to change a repository

git remote set-url origin https://some@bitbucket.org/some/some_st.git

new repository

git remote add origin https://some@bitbucket.org/some/test.git 
git push -u origin master

to delete a branch locally

git branch -d fix-protobaz

to delete a branch on the server

git push --delete origin fix-protobaz

to remove a file from the index

git rm --cached --ignore-unmatch path/file.js

to create a new branch

git branch some_branch

to create a new branch and immediately switch to it

git checkout -b some_branch

to switch to another branch

git checkout some_branch

to edit last commit comment

git commit --amend -m "new comment"

discard last commit but save changes

git reset HEAD~

delete last commit and delete changes

git reset --hard HEAD~

cancel the merge (for example, if you don’t want to resolve conflicts)

git merge --abort

renaming the local master branch to main

git branch -m master main
author
Author: Igor Rybalko
I have been working as a front-end developer since 2014. My main technology stack is Vue.js and WordPress.

Similar posts:

Leave a Reply

Your email address will not be published. Required fields are marked *