Git Workflow: Init, Status, Add, Commit, Push, Pull, Branch, Merge, Cherry-Pick, Pull Requests

⚙️ Git Workflow 1️⃣ Initialize Git git init Creates a hidden .git folder to track changes. Check it using: ls -la 2️⃣ Check Repo Status git status Shows if files are tracked, untracked, or committed. 3️⃣ Add Files git add filename Adds files to the staging area for tracking. Add all files: git add . 4️⃣ Commit Changes git commit -m "Added new feature" Saves a checkpoint with your message. 5️⃣ View Changes git diff # Show modifications git log # Show commit history 6️⃣ Undo or Go Back git reset --hard <commit-id> Goes back to a specific commit version. 🚀 Push Code to GitHub Steps: Create a GitHub account. Create a new repository. Connect local repo to GitHub: git remote add origin <repo_URL> Push your code: git push -u origin main 🔄 Pull and Fetch git pull Fetch and merge latest changes from remote git fetch Fetch updates but don’t merge automatically Use pull to get updates + merge. Use fetch when you just want to see new updates before merging. ⚙️ .gitignore File .gitignore tells Git which files to ignore while tracking. 🌿 Git Branching Strategy Why Use Branches? To work on new features or bug fixes without breaking main code. Makes teamwork smoother and organized. Common Branch Types Main / Master Branch: Always stable and production-ready. Feature Branch: Used to develop new features. Release Branch: Used for preparing code for deployment. Hotfix Branch: Used for urgent fixes in production. 🔄 Branch Commands git branch # List all branches git checkout -b feature1 # Create and switch to new branch git checkout main # Switch back to main branch git merge feature1 # Merge feature branch into main 🔁 Merge, Rebase, and Cherry-Pick 🔸 Merge Combines code from one branch into another. Keeps all commit history. 🔸 Rebase Rewrites commits in a straight line (clean history). Commonly used in professional DevOps workflows. 🔸 Cherry-Pick Pick a specific commit from one branch to another: git cherry-pick <commit-id> 👥 Pull Requests (PR) Used on GitHub when one branch wants to merge into another. Allows code review and approval before merging. Ensures quality and teamwork. 🧩 Example Git Workflow in Real Projects Developer creates a feature branch → works on code. Runs tests and commits changes. Pushes the branch to GitHub. Opens a Pull Request (PR) for review. Once approved → merged into main branch → deployed. Done😎 😎 #GitGithub #Devops

To view or add a comment, sign in

Explore content categories