Thursday, February 6, 2025

Git Commands.

 Double-click on the image to zoom-out ...Larger.

To return to Home page: Refresh Page or Take ESC Button on Keyboard.

Essential Git Commands

Git is a powerful version control system, and here are some of the most commonly used commands:

1. Setup & Configuration

git --version # Check Git version git config --global user.name "Devopspat35" git config --global user.email "patemf2021@yahoo.com" git config --list # View current Git configuration

2. Creating & Cloning Repositories

git init # Initialize a new Git repository git clone <repo_url> # Clone an existing repository

3. Working with Branches

git branch # List all branches git branch <branch_name> # Create a new branch git checkout <branch_name> # Switch to another branch git checkout -b <branch_name> # Create and switch to a new branch git merge <branch_name> # Merge a branch into the current branch git branch -d <branch_name> # Delete a branch git branch -D <branch_name> # Force delete a branch

4. Staging & Committing Changes

git status # Check status of changes git add <file> # Stage a specific file git add . # Stage all changes git commit -m "Commit message" # Commit staged changes git commit --amend -m "New message" # Modify the last commit message

5. Viewing History & Logs

git log # View commit history git log --oneline --graph --all # Compact history with branches git show <commit_hash> # View details of a specific commit git diff # Show unstaged changes git diff --staged # Show staged changes

6. Undoing Changes

git restore <file> # Discard changes in a file git reset HEAD <file> # Unstage a file git reset --hard <commit_hash> # Reset to a specific commit and discard changes

7. Pushing & Pulling Code

git remote -v # View remote repositories git push origin <branch> # Push changes to remote git pull origin <branch> # Pull latest changes from remote git fetch # Fetch latest changes without merging git rebase <branch> # Reapply commits on top of another branch

8. Working with Tags

git tag # List all tags git tag -a v1.0 -m "Version 1.0" # Create an annotated tag git push origin --tags # Push tags to remote git tag -d <tag_name> # Delete a tag

9. Handling Merge Conflicts

git merge <branch> # Merge a branch # If conflicts occur, manually resolve them in the affected files git add <file> # Mark conflicts as resolved git commit -m "Resolved merge conflict"

10. Stashing Changes

git stash # Save changes temporarily git stash list # View stashed changes git stash apply # Apply the latest stashed changes git stash drop # Remove the latest stash git stash pop # Apply and remove the latest stash

No comments:

Post a Comment

AWS DynamoDB | Integration With S3 Bucket.

  AWS DynamoDB ↔ S3 integration , View: What DynamoDB ↔ S3 integration is,   How to use DynamoDB ↔ S3 integration,   Why uses DynamoDB ↔  S3...