Logo

dev-resources.site

for different kinds of informations.

Essential Git Commands Every Developer Should Know

Published at
12/26/2024
Categories
gitcommands
versioncontrol
gittutorial
gitforbeginners
Author
abhay_yt_52a8e72b213be229
Author
25 person written this
abhay_yt_52a8e72b213be229
open
Essential Git Commands Every Developer Should Know

Essential Git Commands

Here’s a list of commonly used Git commands, categorized for convenience:


1. Setup and Configuration

  • Check Git Version:
  git --version
Enter fullscreen mode Exit fullscreen mode
  • Configure Username:
  git config --global user.name "Your Name"
Enter fullscreen mode Exit fullscreen mode
  • Configure Email:
  git config --global user.email "[email protected]"
Enter fullscreen mode Exit fullscreen mode
  • View Configuration:
  git config --list
Enter fullscreen mode Exit fullscreen mode

2. Repository Management

  • Initialize a Repository:
  git init
Enter fullscreen mode Exit fullscreen mode
  • Clone a Repository:
  git clone <repository-url>
Enter fullscreen mode Exit fullscreen mode
  • View Repository Status:
  git status
Enter fullscreen mode Exit fullscreen mode

3. Working with Files

  • Add Files to Staging Area:
  git add <file>   # Add a specific file
  git add .        # Add all changes in the current directory
Enter fullscreen mode Exit fullscreen mode
  • Commit Changes:
  git commit -m "Your commit message"
Enter fullscreen mode Exit fullscreen mode
  • Remove Files:
  git rm <file>
Enter fullscreen mode Exit fullscreen mode
  • Move/Rename Files:
  git mv <old_filename> <new_filename>
Enter fullscreen mode Exit fullscreen mode

4. Branching and Merging

  • Create a New Branch:
  git branch <branch-name>
Enter fullscreen mode Exit fullscreen mode
  • Switch to a Branch:
  git checkout <branch-name>
Enter fullscreen mode Exit fullscreen mode
  • Create and Switch to a New Branch:
  git checkout -b <branch-name>
Enter fullscreen mode Exit fullscreen mode
  • Merge a Branch:
  git merge <branch-name>
Enter fullscreen mode Exit fullscreen mode
  • Delete a Branch:
  git branch -d <branch-name>
Enter fullscreen mode Exit fullscreen mode

5. Remote Repositories

  • Add a Remote Repository:
  git remote add origin <repository-url>
Enter fullscreen mode Exit fullscreen mode
  • View Remote Repositories:
  git remote -v
Enter fullscreen mode Exit fullscreen mode
  • Push Changes to Remote Repository:
  git push origin <branch-name>
Enter fullscreen mode Exit fullscreen mode
  • Pull Changes from Remote Repository:
  git pull origin <branch-name>
Enter fullscreen mode Exit fullscreen mode
  • Fetch Changes from Remote:
  git fetch
Enter fullscreen mode Exit fullscreen mode

6. Viewing and Inspecting

  • View Commit History:
  git log
Enter fullscreen mode Exit fullscreen mode
  • View a Specific Commit:
  git show <commit-hash>
Enter fullscreen mode Exit fullscreen mode
  • View Changes in Files:
  git diff
Enter fullscreen mode Exit fullscreen mode
  • View Changes in Staged Files:
  git diff --staged
Enter fullscreen mode Exit fullscreen mode
  • List Branches:
  git branch
Enter fullscreen mode Exit fullscreen mode

7. Undo Changes

  • Unstage Files:
  git reset <file>
Enter fullscreen mode Exit fullscreen mode
  • Undo Last Commit (Keep Changes):
  git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode
  • Undo Last Commit (Discard Changes):
  git reset --hard HEAD~1
Enter fullscreen mode Exit fullscreen mode
  • Discard Unstaged Changes:
  git checkout -- <file>
Enter fullscreen mode Exit fullscreen mode

8. Stashing

  • Save Changes Temporarily:
  git stash
Enter fullscreen mode Exit fullscreen mode
  • Apply Stashed Changes:
  git stash apply
Enter fullscreen mode Exit fullscreen mode
  • List Stashes:
  git stash list
Enter fullscreen mode Exit fullscreen mode
  • Drop a Stash:
  git stash drop
Enter fullscreen mode Exit fullscreen mode

9. Tags

  • Create a Tag:
  git tag <tag-name>
Enter fullscreen mode Exit fullscreen mode
  • List Tags:
  git tag
Enter fullscreen mode Exit fullscreen mode
  • Push Tags to Remote:
  git push origin <tag-name>
Enter fullscreen mode Exit fullscreen mode

10. Collaboration

  • Rebase:
  git rebase <branch-name>
Enter fullscreen mode Exit fullscreen mode
  • Cherry-pick a Commit:
  git cherry-pick <commit-hash>
Enter fullscreen mode Exit fullscreen mode
  • Resolve Merge Conflicts:

    • Edit conflicting files manually.
    • Stage resolved files:
    git add <file>
    
    • Complete the merge:
    git commit
    

These commands cover most Git functionalities for beginners and intermediate users. If you need clarification or advanced commands, feel free to ask! 😊

versioncontrol Article's
30 articles in total
Favicon
Do You Care About Commit Messages?
Favicon
GitHub vs. GitLab vs. Bitbucket
Favicon
Git Hosting Services: A Comparison of GitHub, GitLab, Bitbucket, and Azure Repos
Favicon
Mastering Git Repositories: Initialization, Cloning, Remotes, URLs, and Submodules
Favicon
A Comprehensive Guide to All Git Commands for Every Developer
Favicon
Committing Changes in Git: A Complete Guide to Git Add, Commit, Messages, and Amending
Favicon
Mastering Git Branching and Merging: A Complete Guide to Git Branches, Merge, Rebase, and More
Favicon
Git Tags
Favicon
Essential Git Commands Every Developer Should Know
Favicon
Master Git: A Comprehensive Beginner to Advanced Guide
Favicon
Understanding Git: The Ultimate Guide with Practical Examples
Favicon
.git
Favicon
Code Like a Librarian: A Beginner's Guide to Git and GitHub
Favicon
Version Control with Git: How to Master It - Best Practices for Efficient Code Management by Git
Favicon
A Beginner’s Guide to GitHub
Favicon
Effective Git Workflow: Managing Version Control in Team Environments
Favicon
π“π²π©πžπ¬ 𝐨𝐟 π•πžπ«π¬π’π¨π§ 𝐂𝐨𝐧𝐭𝐫𝐨π₯ π’π²π¬π­πžπ¦π¬:
Favicon
Azure DevOps Series - Azure Repos
Favicon
Mastering DevOps Branching: Your Ultimate Guide to Git Flow, Trunk, Tag-Based, and Hybrid Strategies
Favicon
Ultimate Git Basics Cheatsheet [Live Doc]
Favicon
Understanding the Role of Git Tags in Version Control
Favicon
Git - Useful Commands
Favicon
Version Control and Git: Essential Tools for Modern Software Development
Favicon
Ultimate Git Branches & Merging Cheatsheet [Live Doc]
Favicon
Git and GitHub for Beginners: A Comprehensive Step-by-Step Guide
Favicon
Bagaimana cara memindahkan branch utama git dari master menjadi main
Favicon
Version Control with Git and GitHub: The Importance and Effective Usage
Favicon
A Comprehensive Guide to Using Footers in Conventional Commit Messages
Favicon
Version Control Best Practices with Git and GitHub
Favicon
Using interactive rebase in Git

Featured ones: