📝 Git Cheat Sheet for Developers

Nikko Ferwelo - Aug 22 - - Dev Community

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! 💻


. . . . . . . . . . . .
Terabox Video Player