Git Commands Cheat Sheet: 15 Essential Git Commands Every Developer Must Know (Beginner to Advanced Guide)

Git Commands Cheat Sheet: 15 Essential Git Commands Every Developer Must Know (Beginner to Advanced Guide)

Git Commands Cheat Sheet: 15 Essential Git Commands Every Developer Must Know

Git is one of the most powerful version control systems used by developers worldwide. Whether you’re working solo or collaborating in a team, mastering Git commands is essential for efficient code management.

In this guide, you’ll learn 15 essential Git commands with examples, helping you streamline your development workflow and avoid common mistakes.

🔹 1. git clone (Copy a Repository)

The git clone command is used to download a remote repository to your local machine.

git clone https://github.com/user/project.git

👉 This creates a complete local copy of the project, including all files and commit history.

🔹 2. git status (Check Repository Status)

This command shows the current state of your working directory.

git status

👉 It helps you identify:

  • Modified files
  • Staged files
  • Untracked files

🔹 3. git add (Stage Changes)

Before committing, you need to stage your changes.

git add file.txt

To add all files:

git add .

👉 Moves changes to the staging area.


🔹 4. git commit (Save Changes)

Commits save your staged changes with a message.

git commit -m "Added login feature"

👉 Think of it as creating a checkpoint in your project.


🔹 5. git push (Upload Code to Remote)

Push your local commits to a remote repository.

git push origin main

👉

  • origin = remote repository
  • main = branch name

🔹 6. git pull (Get Latest Code)

Fetches and merges the latest changes from the remote repository.

git pull origin main

👉 Best practice: Always pull before starting work to avoid conflicts.


🔹 7. git fetch (Download Changes Only)

Downloads changes without merging.

git fetch

👉 Useful for safely reviewing updates before applying them.


🔹 8. git branch (Manage Branches)

List all branches:

git branch

Create a new branch:

git branch feature-login

👉 Helps in working on features independently.


🔹 9. git checkout (Switch Branches)

Switch to another branch:

git checkout feature-login

Create and switch:

git checkout -b feature-login

👉 Used for navigation and restoring files.


🔹 10. git merge (Combine Branches)

Merge one branch into another.

git checkout main
git merge feature-login

👉 Integrates feature code into the main branch.


🔹 11. git log (View Commit History)

Shows commit history.

git log

Short version:

git log --oneline

👉 Helps track changes and history.


🔹 12. git diff (See Code Changes)

Displays differences between files.

git diff

👉 Useful for reviewing changes before committing.


🔹 13. git reset (Undo Staging)

Remove a file from staging area:

git reset file.txt

👉 Does not delete changes, only unstages them.


🔹 14. git stash (Save Work Temporarily)

Save unfinished work:

git stash

Restore it later:

git stash pop

👉 Perfect when switching branches without committing.


🔹 15. git remote (Manage Remote Repositories)

View remote repositories:

git remote -v

Add a new remote:

git remote add origin https://github.com/user/project.git

⚠️ Important Git Workflow Tip (Real-World Practice)

👉 Before pushing code:

  • Always pull from pencil_dev_env
  • Only push to basant_dev
  • Add proper tags when required

This ensures:

  • No merge conflicts
  • Clean collaboration
  • Proper version tracking

📌 Best Practices for Using Git

  • ✅ Commit frequently with meaningful messages
  • ✅ Pull before starting work
  • ✅ Use branches for new features
  • ✅ Avoid pushing directly to main
  • ✅ Use git fetch for safe updates
  • ✅ Keep your repository clean

🎯 Conclusion

Mastering these Git commands will significantly improve your development workflow. Whether you’re a beginner or an experienced developer, these commands form the foundation of efficient version control.

Start practicing today and make Git your best development companion 🚀

How to add multiple images into database using mysql and php

How to add multiple images into database using mysql and php

// start multiple image

$stmt = $conn->prepare(“INSERT INTO cat_images (img_url, cat_id) VALUES (?, ?)”);
$stmt->bind_param(“si”, $imagePath, $cat_id);
$uploadedImages = $_FILES[‘images’];

$cat_id = $conn->insert_id;

foreach ($uploadedImages[‘name’] as $key => $value) {
$targetDir = “main-images/galleries/”;
$fileName = basename($uploadedImages[‘name’][$key]);
$targetFilePath = $targetDir . $fileName;
if (file_exists($targetFilePath)) {
echo “Sorry, file already exists.<br>”;
} else {
if (move_uploaded_file($uploadedImages[“tmp_name”][$key], $targetFilePath)) {
$imagePath = $targetFilePath;
$stmt->execute();
echo “The file ” . $fileName . ” has been uploaded successfully.<br>”;
} else {
echo “Sorry, there was an error uploading your file.<br>”;
}
}
}
$stmt->close();
$conn->close();

// end multiple image

Email does not comply with addr-spec of RFC 2822. Laravel

This error message indicates that the email address you’re attempting to use doesn’t adhere to the specific formatting guidelines outlined in RFC 2822. This RFC is a fundamental standard for email addresses, defining the correct syntax and structure.

Common Reasons for Non-Compliance:

  1. Missing or Incorrect ‘@’ Symbol: The ‘@’ symbol separates the local part (the username) from the domain part (the email provider). Its absence or incorrect placement is a common cause of this error.
  2. Invalid Local Part: The local part can contain letters (both uppercase and lowercase), numbers, underscores, hyphens, and periods. However, it cannot start or end with a period, and consecutive periods are not allowed.
  3. Invalid Domain Part: The domain part typically consists of one or more domain names separated by periods. Each domain name should adhere to specific rules, such as not starting or ending with a hyphen.
  4. Whitespace or Special Characters: Email addresses should not contain any whitespace characters (spaces, tabs, etc.) or special characters (except those allowed in the local and domain parts).
  5. Case Sensitivity: While email addresses are generally case-insensitive, some systems might be more strict about case. Ensure that the case of the characters matches the expected format.

Example of a Valid Email Address:

 

Example of an Invalid Email Address:

john [email protected]  // Missing '@' and whitespace
[email protected] // Invalid local part with consecutive periods
example@ // Missing domain part

 

Troubleshooting Steps:

  1. Double-check the Email Address: Carefully review the email address for any typos, missing characters, or incorrect formatting.
  2. Consult RFC 2822: If you need more detailed information, refer to the RFC 2822 specification.
  3. Use an Online Validation Tool: There are many online tools available that can validate email addresses based on RFC 2822.

By addressing these common issues and following the guidelines in RFC 2822, you can ensure that your email addresses are valid and compliant.

Simple solution to fix this issue is:
make array of multiple emails like below:

$emails = [‘[email protected]’, ‘[email protected]’];
this issue comes when we want to add multiple email ids for receiving emails.
Hope you Understand.