๐ Git Cheat Sheet for Developers
Nikko Ferwelo
Posted on August 22, 2024
Hello everyone! ๐
Hereโs a comprehensive Git Cheat Sheet to help you manage your code versioning and collaboration more effectively. Whether youโre just starting out or need a quick reference, this guide is here to assist.
Letโs dive in!
๐ Core Concepts
- Git: Distributed version control system for tracking changes in source code.
๐ฆ Git Commands and Concepts
-
git init
: Initializes a new Git repository.
git init
-
git clone
: Clones an existing repository.
git clone https://github.com/username/repository.git
-
git add
: Stages changes for commit.
git add file.txt
git add .
-
git commit
: Commits staged changes to the repository.
git commit -m "Commit message"
-
git status
: Shows the status of changes.
git status
-
git log
: Displays commit history.
git log
-
git diff
: Shows differences between changes.
git diff
-
git branch
: Lists, creates, or deletes branches.
git branch
git branch new-branch
git branch -d old-branch
-
git checkout
: Switches branches or restores working directory files.
git checkout branch-name
git checkout -b new-branch
-
git merge
: Merges changes from one branch into another.
git merge branch-name
-
git pull
: Fetches and merges changes from a remote repository.
git pull origin main
-
git push
: Pushes local commits to a remote repository.
git push origin branch-name
-
git remote
: Manages remote repositories.
git remote -v
git remote add origin https://github.com/username/repository.git
git remote remove origin
-
git fetch
: Retrieves updates from a remote repository without merging.
git fetch origin
-
git rebase
: Reapplies commits on top of another base tip.
git rebase branch-name
-
git reset
: Resets current HEAD to a specified state.
git reset --hard HEAD~1
git reset --soft HEAD~1
-
git stash
: Stashes changes in a dirty working directory.
git stash
git stash pop
-
git tag
: Tags specific commits with a label.
git tag v1.0
git tag -a v1.0 -m "Version 1.0"
-
git cherry-pick
: Applies changes from specific commits.
git cherry-pick commit-hash
-
git revert
: Creates a new commit that undoes changes from a previous commit.
git revert commit-hash
-
git config
: Configures Git settings.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
-
git log --graph
: Visualizes the commit history as a graph.
git log --graph --oneline
-
git blame
: Shows who last modified each line of a file.
git blame file.txt
Connect with me:
- LinkedIn: https://www.linkedin.com/in/nikko-ferwelo-358b11213
- GitHub: https://github.com/NullVoidKage
Feel free to reach out or follow me for more insights and tips on version control with Git. Happy coding! ๐ป
๐ ๐ช ๐
๐ฉ
Nikko Ferwelo
Posted on August 22, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.