๐Ÿ“ Git Cheat Sheet for Developers

nullvoidkage

Nikko Ferwelo

Posted on August 22, 2024

๐Ÿ“ Git Cheat Sheet for Developers

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
Enter fullscreen mode Exit fullscreen mode
  • git clone: Clones an existing repository.
  git clone https://github.com/username/repository.git
Enter fullscreen mode Exit fullscreen mode
  • git add: Stages changes for commit.
  git add file.txt
  git add .
Enter fullscreen mode Exit fullscreen mode
  • git commit: Commits staged changes to the repository.
  git commit -m "Commit message"
Enter fullscreen mode Exit fullscreen mode
  • git status: Shows the status of changes.
  git status
Enter fullscreen mode Exit fullscreen mode
  • git log: Displays commit history.
  git log
Enter fullscreen mode Exit fullscreen mode
  • git diff: Shows differences between changes.
  git diff
Enter fullscreen mode Exit fullscreen mode
  • git branch: Lists, creates, or deletes branches.
  git branch
  git branch new-branch
  git branch -d old-branch
Enter fullscreen mode Exit fullscreen mode
  • git checkout: Switches branches or restores working directory files.
  git checkout branch-name
  git checkout -b new-branch
Enter fullscreen mode Exit fullscreen mode
  • git merge: Merges changes from one branch into another.
  git merge branch-name
Enter fullscreen mode Exit fullscreen mode
  • git pull: Fetches and merges changes from a remote repository.
  git pull origin main
Enter fullscreen mode Exit fullscreen mode
  • git push: Pushes local commits to a remote repository.
  git push origin branch-name
Enter fullscreen mode Exit fullscreen mode
  • git remote: Manages remote repositories.
  git remote -v
  git remote add origin https://github.com/username/repository.git
  git remote remove origin
Enter fullscreen mode Exit fullscreen mode
  • git fetch: Retrieves updates from a remote repository without merging.
  git fetch origin
Enter fullscreen mode Exit fullscreen mode
  • git rebase: Reapplies commits on top of another base tip.
  git rebase branch-name
Enter fullscreen mode Exit fullscreen mode
  • git reset: Resets current HEAD to a specified state.
  git reset --hard HEAD~1
  git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode
  • git stash: Stashes changes in a dirty working directory.
  git stash
  git stash pop
Enter fullscreen mode Exit fullscreen mode
  • git tag: Tags specific commits with a label.
  git tag v1.0
  git tag -a v1.0 -m "Version 1.0"
Enter fullscreen mode Exit fullscreen mode
  • git cherry-pick: Applies changes from specific commits.
  git cherry-pick commit-hash
Enter fullscreen mode Exit fullscreen mode
  • git revert: Creates a new commit that undoes changes from a previous commit.
  git revert commit-hash
Enter fullscreen mode Exit fullscreen mode
  • git config: Configures Git settings.
  git config --global user.name "Your Name"
  git config --global user.email "your.email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • git log --graph: Visualizes the commit history as a graph.
  git log --graph --oneline
Enter fullscreen mode Exit fullscreen mode
  • git blame: Shows who last modified each line of a file.
  git blame file.txt
Enter fullscreen mode Exit fullscreen mode

Connect with me:

Feel free to reach out or follow me for more insights and tips on version control with Git. Happy coding! ๐Ÿ’ป


๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
nullvoidkage
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.

Related

ยฉ TheLazy.dev

About