DEV Community

Sameer Gurung
Sameer Gurung

Posted on • Originally published at Medium on

Git basics in a FLASH!

Photo by Yancy Min on Unsplash

Hello World! Apart from adding, committing and pushing files to the repository, here are some common git operations, in a flash!

1. Branching

Branching is necessary when you want to work on a new feature (or for other reasons) and separate your code from master branch.

Create a branch and checkout:

git checkout -b nameOfYourNewBranch

Delete a local branch :

git branch -d branchName

Delete a remote branch:

git push origin -d branchName

2. Merging

Merging a branch is necessary because you might want to merge a feature branch to the master branch.

# Start a new feature

git checkout -b new-feature master

# Edit some files

git add <file>

git commit -m “Start a feature”

# Edit some files

git add <file>

git commit -m “Finish a feature”

# Merge in the new-feature branch

git checkout master

git merge new-feature

# Delete the new-feature branch

git branch -d new-feature

3. Stashing

Stashing is used when you temporarily want to put away your change and have the clean woking tree. Don’t worry, you will be able to get your stashed changes back.

Stashing current work:

git stash

Listing stashes

git stash list

Importing latest stash:

git stash pop

Importing particular stash if more than one:

git stash pop stash@{n}

Dropping stash:

git stash drop stash@{n}

Here, n refers to a number, 0, 1, 2… which represents which stash to delete.

4. Cleaning Cache

Cleaning cache is required when you want to remove previously added files which you don’t want to track anymore.

Clean all git cache:

git rm -r --cached .

Clean cache of only required file:

git rm fileName --cached

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay