DEV Community

Anass Assim
Anass Assim

Posted on β€’ Edited on

8 3

πŸ“ Git Cheat Sheet πŸš€

πŸ“ First Steps: Start and Configure A Git πŸš€

Command Description
git init Creates a new Git repository in the current folder.
git config --global -l Sets or views Git settings, like username and email ,...
git config $option "text" Sets a Git configuration option to a specified value.

πŸ“… Day-to-Day Work:

Command Description
git status Displays the current status of the working directory and staging area.
git add $File_Name Stages a file for the next commit.
git rm --cached $File_Name Untrack a file without deleting it locally.
git commit -m "Message" Records changes to the repository with a descriptive message.
git diff Displays differences between changes and the last commit.
git log --oneline Displays a concise summary of commits in a single line.
git checkout $hash Switches to the specified commit by its hash.
git fetch Retrieves updates from the remote repository without merging.
git pull Fetches and merges updates from the remote repository.
git push Uploads local commits to the remote repository.
git restore $FileName Restores the specified file to the last committed state.
git blame Shows line-by-line authorship for each line in a file.
git stash Temporarily saves changes that are not ready to be committed.
git tag Creates a marker for a specific commit, often used for releases.

πŸ“‚ Files:

Command Description
.gitconfig File Stores Git settings like username and preferences.
.gitignore file specifies files and directories for Git to ignore.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (5)

Collapse
 
programmerraja profile image
Boopathi β€’

This is a fantastic Git cheat sheet! I especially appreciate the inclusion of git restore and git blame. These commands are super helpful for quickly reverting changes or understanding code history.

Collapse
 
ciscoanass profile image
Anass Assim β€’

Thanks! Glad you liked it! 😊 git restore and git blame are super useful. Let me know if you need more!

Collapse
 
getcyber profile image
Dan Duran β€’ β€’ Edited

Messed up on your code and want to revert to the last commit you did?

git reset --hard HEAD # Reverts your code to the last commit.

Want to go back exactly N commits instead?
git reset --hard HEAD~N # Resets to N commits ago without needing a specific commit hash.

Need to find a specific older commit hash instead?
git log -n N # Shows the latest N commits so you can grab a specific hash.
git reset --hard # Reset to that specific commit hash.

Used this hundreds of times!
;)

Collapse
 
ciscoanass profile image
Anass Assim β€’

Perfect tips! Thanks for sharing! <3

Collapse
 
hari_krishnan_bc5a45362e2 profile image
Hari Krishnan β€’

Nice

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

πŸ‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Communityβ€”every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple β€œthank you” goes a long wayβ€”express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay