Essential Git Practices for Corporate Development

Bhavana N.BBhavana N.B
5 min read

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

  1. 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.

  1. git clone: Clones an existing remote Git repository to your local machine.
git clone <repository-url>
  1. git checkout: Switches between branches or restores files.
# working on existing repository
git checkout <latest-branch-name>
git pull origin <latest-branch-name>
  1. 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
  1. git add: Stages changes for the next commit.
git add <file-name>          # Stage a particular file
git add .                    # Stage all changes
  1. git commit: Saves a snapshot of staged changes with a message.
 git commit -m "prefix: Your message"
PrefixDescription
featA new feature
fixA bug fix
docsDocumentation changes only
styleChanges that do not affect logic (e.g., formatting, whitespace, semicolons)
refactorCode changes that neither fix a bug nor add a feature
perfPerformance improvement
testAdding or updating tests
buildChanges that affect the build system or dependencies
ciContinuous Integration-related changes (e.g., GitHub Actions, Jenkins)
choreOther changes that don’t modify src or test files (e.g., updates to .gitignore)
revertReverts a previous commit
  1. 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
  1. npm run build:

    This command creates a production-ready version of your application by running the build script defined in your project's package.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)
  1. git status: Shows the current state of your working directory.
git status

Displays staged, unstaged, and untracked files.

  1. git push: Pushes your local commits to the remote repository.
git push origin <branch-name>
  1. 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
  1. 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
  1. 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
  1. git log: Shows a detailed commit history.
git log                    # Full history
git log --oneline          # Short version
git log --graph --oneline  # Visual tree of commits
  1. 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.
  1. git diff: Shows the difference between changes.
git diff                   # View unstaged changes
git diff --staged          # View staged changes
  1. 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

3
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.