πŸ“ Essential Git Commands for Local and Production Environments

Author: neptune | 17th-Jul-2025
#Github #IT

Version control with Git is crucial for managing your codebase efficiently. This article covers important Git commands used in production and local environments with practical examples.


βœ… 1. Checking Commit Differences Between Local and Remote

Remote repo : origin/feature/2025

Local repo : feature/2025

πŸ”· a. View Commits Only in Local

git log origin/feature/2025..feature/2025 --oneline

πŸ” Explanation: Shows commits that exist locally but not in the remote branch.

βœ”οΈ Example Output:

8e3c1db Updated home page styles

d2a4f32 Added new API endpoint for views



πŸ”· b. View Commits Only in Remote

git log feature/2025..origin/feature/2025 --oneline


πŸ” Explanation: Shows commits that exist in the remote but not locally.

βœ”οΈ Example Output:

f6d7aab Bug fix in auth middleware

c8e9b23 Updated README with deployment steps



 2. Visualizing Branch Differences

git log --oneline --graph --decorate --abbrev-commit origin/feature/2025..feature/2025


πŸ” Explanation: Visualizes commits only in your local branch compared to remote with a graph view.

βœ”οΈ Example Output:

* d2a4f32 (HEAD -> feature/2025) Added new API endpoint for views

* 8e3c1db Updated home page styles



βœ… 3. Checking File Differences Between Local and Remote

πŸ”· a. Local vs Remote

git diff origin/feature/2025..feature/2025

πŸ” Explanation: Shows file changes in local that are not in remote.


πŸ”· b. Remote vs Local

git diff feature/2025..origin/feature/2025

πŸ” Explanation: Shows file changes in remote that are not in local.


βœ… 4. Fetch Remote Changes Without Merging

git fetch


πŸ” Explanation: Downloads updates from remote branches without merging them into your local branch.


βœ… 5. Pulling Changes with Different Strategies

πŸ”· a. Merge (Default)

sudo git pull --no-rebase

Merges remote changes into local branch, creating a merge commit if necessary.


πŸ”· b. Rebase

sudo git pull --rebase

Reapplies your local commits on top of remote commits for a linear history.


πŸ”· c. Fast-Forward Only

sudo git pull --ff-only

Updates your branch only if it can be fast-forwarded; otherwise, it aborts.


πŸ”· d. Configure Pull Behavior Permanently

git config pull.rebase true   # Always rebase on pull

git config pull.rebase false  # Always merge on pull



βœ… 6. Removing a File from Git Tracking but Keeping It Locally

πŸ”· Example: Ignoring db.sqlite3

sudo git rm --cached mysite/db.sqlite3

echo "/mysite/db.sqlite3" >> .gitignore

sudo git add .gitignore

sudo git commit -m "Stop tracking db.sqlite3 and update .gitignore"

sudo git push


βœ”οΈ Explanation:

  • git rm --cached untracks the file while keeping it locally.

  • Adds it to .gitignore to prevent future tracking


βœ… 7. Other Important Git Commands for Production and Local

Task

Command

Check current branch

git branch

Switch branch

git checkout branch_name

Create new branch

git checkout -b new_branch

Delete branch

git branch -d branch_name

View remote branches

git branch -r

View all branches

git branch -a

Stage all changes

git add .

Commit changes

git commit -m "message"

View status

git status

View last commit

git log -1

Force push (use with caution)

git push --force

Discard local changes

git checkout -- file_name

Reset to remote state (dangerous)

git reset --hard origin/branch_name


πŸ” Summary

These Git commands help you:

  • Manage divergent branches

  • Check commit differences

  • Pull and merge efficiently

  • Avoid database merge conflicts in production

  • Maintain clean Git practices

Keep this as your Git command cheat sheet for daily development, deployments, and server management.




Related Blogs
TCS Generative AI E1 Course 6618 Assessment Questions and Answers
Author: neptune | 07th-Sep-2024
#IT #TCS
How can Generative AI be used in virtual reality applications? Answer: B) To simulate a realistic environment...

Elon Musk's Innovative Move: Twitter's Path to Monetization
Author: neptune | 12th-Aug-2023
#IT #Story
Elon Musk empowers Twitter users with monetization tools, offering exclusive content options and video programs, reshaping the platform's revenue landscape...

List of Top 15 Product-based Companies In India
Author: neptune | 02nd-Oct-2022
#IT
Adobe Inc. initially called Adobe Systems Incorporated, is an American worldwide program organization. Products: Acrobat Pro, Photoshop, Illustrator, Spark, InCopy, etc...

Different types of software testing ?
Author: neptune | 27th-Jul-2022
#Testing #IT
Testing is the process to improve the performance of software. Examples: Unit, Integration, Regression, Smoke, Alpha, Beta, System, Stress Performance, Object-Oriented Testing etc...

GoodbyeX: A Step-by-Step Guide to Remove the "X" Branding from Twitter
Author: neptune | 26th-Jul-2023
#Github #Projects
Twitter has been known for its continuous updates and changes to its user interface. One such change was the introduction of the "X" branding, which might not be appreciated by all users...

Commonly Used Abbreviations In Information Technology.
Author: neptune | 22nd-May-2022
#IT
We came up with commonly used acronym in IT Industry like IaaS, ASCII, IAM, TLS, SSL, BYOD, JSON etc...

Will Infosys and TCS Meet the Same Fate as India's Cotton Mills?
Author: neptune | 12th-Jun-2024
#IT #TCS
India's textile industry serves as a cautionary tale for today's tech outsourcing leaders, Infosys, TCS, and other Indian IT giants must navigate these changes carefully, continually adapting...

Git - Recovering Discarded Changes
Author: neptune | 13th-Jul-2023
#Github #Problem Solving
We will follow a scenario where a developer is working on a web application and needs to recover a discarded commit to reintroduce a specific feature...

Top 5 Highly Demanding IT Jobs in 2023.
Author: neptune | 02nd-Apr-2023
#IT #Jobs
Nowadays Jobs are raining in the IT Industry for multiple profiles with a huge number of openings. We will cover the top 5 IT Jobs in the coming year or later...

Generating an SSH Key and Adding it to Your GitLab Account
Author: neptune | 19th-Sep-2023
#Github
SSH keys provide a secure way to authenticate yourself to GitLab without the need for a username and password...

List of Items Carry to Canada as a TCS Employee (Toronto)
Author: neptune | 01st-Jan-2025
#IT #TCS
Traveling to Toronto, Canada, for work as a TCS employee requires careful preparation to ensure a smooth transition...

Why Are TCS, Infosys, and Wipro Posting More Jobs Now 2024?
Author: neptune | 23rd-Jun-2024
#IT #TCS
Indian IT companies are back in action, reviewing numerous resumes and posting more job opportunities...

REALITY of Working in a Corporate MNC: TCS and Infosys ?
Author: neptune | 23rd-Jun-2024
#IT #TCS
One of the primary attractions of working in a corporate MNC such as TCS or Infosys is the job security it offers...

TCS Q1 FY26 Results: Weak Growth Despite AI Push
Author: neptune | 13th-Jul-2025
#IT #TCS
TCS's Q1 FY26 results reflect persistent challenges amid economic uncertainties and deal delays...

TCS Launches β€œGEN AI Tech Pathway” in its STEM Education Program goIT 2025
Author: neptune | 13th-Jul-2025
#AI #IT #TCS
TCS’s launch of the Gen AI Tech Pathway is a clear step towards fostering AI literacy among youth, strengthening India’s position as a global digital innovation hub...

View More