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
Hereβs a list of commonly used Git commands, categorized for convenience:
1. Setup and Configuration
- Check Git Version:
git --version
- Configure Username:
git config --global user.name "Your Name"
- Configure Email:
git config --global user.email "[email protected]"
- View Configuration:
git config --list
2. Repository Management
- Initialize a Repository:
git init
- Clone a Repository:
git clone <repository-url>
- View Repository Status:
git status
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
- Commit Changes:
git commit -m "Your commit message"
- Remove Files:
git rm <file>
- Move/Rename Files:
git mv <old_filename> <new_filename>
4. Branching and Merging
- Create a New Branch:
git branch <branch-name>
- Switch to a Branch:
git checkout <branch-name>
- Create and Switch to a New Branch:
git checkout -b <branch-name>
- Merge a Branch:
git merge <branch-name>
- Delete a Branch:
git branch -d <branch-name>
5. Remote Repositories
- Add a Remote Repository:
git remote add origin <repository-url>
- View Remote Repositories:
git remote -v
- Push Changes to Remote Repository:
git push origin <branch-name>
- Pull Changes from Remote Repository:
git pull origin <branch-name>
- Fetch Changes from Remote:
git fetch
6. Viewing and Inspecting
- View Commit History:
git log
- View a Specific Commit:
git show <commit-hash>
- View Changes in Files:
git diff
- View Changes in Staged Files:
git diff --staged
- List Branches:
git branch
7. Undo Changes
- Unstage Files:
git reset <file>
- Undo Last Commit (Keep Changes):
git reset --soft HEAD~1
- Undo Last Commit (Discard Changes):
git reset --hard HEAD~1
- Discard Unstaged Changes:
git checkout -- <file>
8. Stashing
- Save Changes Temporarily:
git stash
- Apply Stashed Changes:
git stash apply
- List Stashes:
git stash list
- Drop a Stash:
git stash drop
9. Tags
- Create a Tag:
git tag <tag-name>
- List Tags:
git tag
- Push Tags to Remote:
git push origin <tag-name>
10. Collaboration
- Rebase:
git rebase <branch-name>
- Cherry-pick a Commit:
git cherry-pick <commit-hash>
-
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! π
gittutorial Article's
4 articles in total
Mastering Git Repositories: Initialization, Cloning, Remotes, URLs, and Submodules
read article
How to Access Git Help: A Comprehensive Guide
read article
Essential Git Commands Every Developer Should Know
currently reading
π Importance of Source Code Control: A Guide to Git
read article
Featured ones: