Essential Git Practices for Corporate Development


1️⃣ What is Git?
Git is a free, open-source, distributed version control system used to track changes in source code during software development.
2️⃣ Key Features of Git
Version Control: Keeps a history of every change made to files.
Distributed: Every developer has a full copy of the codebase (repository), including the entire history.
Branching & Merging: Easily create separate branches for new features or experiments, and merge them back when ready.
Collaboration: Helps teams work together on the same project without conflicts.
3️⃣ Common Git Terms
Repository (repo): A folder that Git tracks.
Commit: A snapshot of your changes with a message explaining what you did.
Branch: A separate line of development.
Merge: Combining changes from different branches.
Push/Pull: Upload/download changes to/from a remote server (e.g., GitHub).
4️⃣ Branching Strategy (Used in Companies)
Companies follow a structured branching model:
main
/master
– stable production code.develop
– active development branch.feature/*
– new features.bugfix/*
– bug fixes.release/*
– pre-release versions.hotfix/*
– emergency production fixes.
5️⃣ Git Commands
- git init: Initializes a new Git repository in your project directory.
git init # Start a new project/repository
Creates a hidden .git
folder to track the project.
- git clone: Clones an existing remote Git repository to your local machine.
git clone <repository-url>
- git checkout: Switches between branches or restores files.
# working on existing repository
git checkout <latest-branch-name>
git pull origin <latest-branch-name>
- git branch: Manages local branches.
git branch # List all local branches
git branch <new-branch-name> # Create a new branch
git checkout <branch-name> # Switch to the branch
git checkout -b <new-branch-name> # Create and switch in one command
- git add: Stages changes for the next commit.
git add <file-name> # Stage a particular file
git add . # Stage all changes
- git commit: Saves a snapshot of staged changes with a message.
git commit -m "prefix: Your message"
Prefix | Description |
feat | A new feature |
fix | A bug fix |
docs | Documentation changes only |
style | Changes that do not affect logic (e.g., formatting, whitespace, semicolons) |
refactor | Code changes that neither fix a bug nor add a feature |
perf | Performance improvement |
test | Adding or updating tests |
build | Changes that affect the build system or dependencies |
ci | Continuous Integration-related changes (e.g., GitHub Actions, Jenkins) |
chore | Other changes that don’t modify src or test files (e.g., updates to .gitignore) |
revert | Reverts a previous commit |
- git pull: Downloads changes from a remote branch and merges them into your current branch.
git fetch origin # Get latest changes without applying them
git log origin/<branch-name> # Inspect fetched commits before merging
git merge origin/<branch-name> # Merges changes from the remote branch into the local branch
git pull origin <branch-name> # Equivalent to fetch + merge
If conflicts occur :
git pull origin <branch-name>
# 🔥 Conflict detected
# 👨💻 Manually resolve conflicts
git add .
git commit -m "Resolved merge conflicts"
git pull origin <branch-name> # Optional - confirms update
npm run build:
This command creates a production-ready version of your application by running the
build
script defined in your project'spackage.json
file. Compiles, bundles, and minifies the code for production.
npm run build
If errors occur during the build process, the terminal will display messages indicating issues such as syntax mistakes, missing modules, or environment misconfigurations.
If errors occur:
# Fix errors, then:
git add .
git commit -m "Fixed build errors"
npm run build # (Optional - rerun build)
- git status: Shows the current state of your working directory.
git status
Displays staged, unstaged, and untracked files.
- git push: Pushes your local commits to the remote repository.
git push origin <branch-name>
- git stash: Temporarily shelves (stashes) uncommitted changes.When you want to switch branches but aren’t ready to commit changes.
git stash # Save changes
git stash pop # Restore them later
git reset: Undo commits or changes.
🛑(--hard) discards local changes irreversibly and can cause data loss, so users should be very cautious.
git reset --soft HEAD~1 # Undo commit, keep changes staged,(HEAD~1) -> the previous commit
git reset --mixed HEAD~1 # Undo commit, keep changes unstaged
git reset --hard HEAD~1 # 🛑 (Be careful with this command❗)Undo commit and discard changes
- git config: Sets Git configuration options like user identity, editor, and behavior.
git config --global user.name "Your Name" # Set name globally
git config --global user.email "you@example.com" # Set email globally
git config --list # View current config
- git log: Shows a detailed commit history.
git log # Full history
git log --oneline # Short version
git log --graph --oneline # Visual tree of commits
- git remote -v : Lists the remote repositories connected to your local repo.
git remote -v # Remotes are repositories hosted on servers (like GitHub) that your local repository syncs with.
- git diff: Shows the difference between changes.
git diff # View unstaged changes
git diff --staged # View staged changes
- git revert: Safely undoes a specific commit by creating a new commit that reverses the changes made in the selected commit (without deleting history).
git revert <commit-hash> #<commit-hash> => A unique alphanumeric ID Git assigns to each commit.Find it from "git log" command
🎉 Happy coding !!!
#git # git command # Web development
Subscribe to my newsletter
Read articles from Bhavana N.B directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Bhavana N.B
Bhavana N.B
I am full stack developer enthusiast.