Day 12 Git Cheatsheet

Agnes Jadhav
3 min readJul 28, 2023

--

Git Basics

Git is a tool that allows to Version Control System

Setup

Set the author name and email that will be attached to your commits.

$git config  - global user.name "Username"
$git config - global user.email "email address"

— flag to set config options for users.

Create an empty Git repository with a specific directory. To initialize the current directory as a git empty repository.

$ git init - Initilize an existing directory as a git repository.

Clone the repository onto a local machine via HTTP or SSH.

$ git clone <url> - Clone the repository to local machine. 

Stage all changes for the next commit.

$ git add < directory>

Commit the staged file to track in git.

$ git commit -m " Message "

List which files are staged, Unstaged, and Untracked.

$ git status 

Display all the commit history.

$ git log 

GIT BRANCH

List all of the branches in your repo.

$ git branch

Create a new branch with the branch name and -b flag to check an existing flag

$ git checkout -b < branch name>

Drop -d flag to delete the branch with the branch name

$ git branch -d < branch name>

To Merge the current branch with another branch

$ git merge < branch>

UNDO CHANGES

To Undo the commit, create a new commit and then apply it to the current branch.

$ git revert <commit>

To undo specific commit

$ git reset <commit_id>

To rebase all the commits between another branch to the current branch

$ git rebase <other_branch_name>

REMOTE

Get the list of all the remote repositories that are connected to a local repository -v flag for verbose display

$ git remote -v 

To add a remote origin URL

$ git remote add origin <remote-git-url>

To remove a remote origin URL.

$ git remote remove origin < remote-git-url >

Adding local repository content to a remote repository.

$ git push origin < Branch-name>

To get all the content from the remote repository to the local repository.

$ git pull origin < branch-name>

To get all the branches from that git remote.

$ git fetch

Cherry Pick

Merge one specific commit from another branch to your current branch

$ git cherry-pick [commit-id]

Temporary Commits

Temporarily save changes you have made in your working directory, without committing them.

$ git stash 

Get a list stack-order of stashed file changes

$ git stash list

write working from the top of the stash stack

$ git stash pop

Thank you for reading my blog!

Happy Learning!

--

--

No responses yet