0% found this document useful (0 votes)
25 views

How To Get Changessds From Master Into a Branch in Git_ - GeeksforGeeks

Uploaded by

Sunil Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

How To Get Changessds From Master Into a Branch in Git_ - GeeksforGeeks

Uploaded by

Sunil Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git?

- GeeksforGeeks

Sale Ends In: 03 : 22 : 05 Full Stack Course HTML CSS JavaScript TypeScript jQuery Angular

How To Get Changes From Master Into a Branch in


Git?
Last Updated : 31 Jul, 2024

Adding changes from the master branch to a different branch is a typical


Git task. This process makes sure that the branch you are working on is
up-to-date with all of the main codebase's modifications and updates.
This can be accomplished in a variety of ways, each appropriate for a
particular scenario and workflow.

In order to make the process understandable, we will cover every angle


that could be taken, go over each step in detail, and include illustrations.
Below are the some approaches to get changes from master into branch
in git.

Table of Content
Merge
Rebase

Method 1: Merge
Merging is the simplest and most common way to get changes from the
master branch into your current branch. It combines the histories of the
two branches.
Step 1: Switch to your branch

git checkout your-branch

Step 2: Fetch the latest changes

git fetch origin

Step 3: Merge master into your branch


We use cookies to ensure you have the best browsing experience on our website. By using our site, you
git merge origin/master
acknowledge that you have read and understood our Cookie Policy & Privacy Policy

Step 4: Resolve any merge conflicts if they arise.


Got It !
https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 1/8
12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks

Step 5: Commit the merge if needed (usually Git handles this automatically).
Example

How To Get Changes From Master Into a Branch in Git

Method 2: Rebase
Rebasing is an alternative to merging that moves your branch's commits
on top of the latest commits in master, providing a cleaner project
history.
Step 1: Switch to your branch

git checkout your-branch

Step 2: Fetch the latest changes

git fetch origin

Step 3: Rebase your branch onto master

git rebase origin/master

Step 4: Resolve any conflicts during the rebase process.


Step 5: Continue the rebase after resolving conflicts

git rebase --continue

Step 6: Force push your branch to update the remote history:

git push origin your-branch --force

Example

We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 2/8
12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks

How To Get Changes From Master Into a Branch in Git

Choosing Between Merge and Rebase

When to Use Merge

Simple Integration: If you want to integrate changes without


rewriting the commit history.
Preserving History: When you want to preserve the chronological
order of commits from both branches.
Team Collaboration: When multiple team members are working on
the same branch, and you want to avoid potential complications with
rebasing.

When to Use Rebase

Clean History: If you prefer a linear project history without merge


commits.
Feature Development: When developing a feature independently
and want to keep your branch up-to-date with the master branch.
Review Simplicity: For making code reviews simpler by having a
linear commit history.

Want to be a Software Developer or a Working Professional looking to


enhance your Software Development Skills? Then, master the concepts
We
ofuse cookies to ensure
Full-Stack you have the bestOur
Development. browsing
Fullexperience on our website. By -using
Stack Development our site,
React and you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Node.js Course will help you achieve this quickly. Learn everything from

https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 3/8
12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks

Front-End to Back-End Development with hands-on Projects and real-


world examples. This course enables you to build scalable, efficient,
dynamic web applications that stand out. Ready to become an expert in
Full-Stack? Enroll Now and Start Creating the Future!

Comment More info Next Article


How to Change Git Default
Branch From Master?

Similar Reads
How to Make the Current Git Branch a Master Branch?
Managing branches effectively is a key part of using Git for version
control. Occasionally, you might find yourself in a situation where the…
3 min read

How to Replace Master Branch with Another Branch in GIT?


In Git, the "master" branch traditionally serves as the primary
development branch in many repositories. However, there are situations…
2 min read

How to Create a Git Branch From Unstaged/Uncommitted Changes …


When working with Git, you might find yourself in a situation where
you've made changes to your files but haven't committed them yet. You…
3 min read

Git Merge Hotfix Branch Into Feature Branch


When working on a software project, you may encounter situations where
a hotfix needs to be applied to a feature branch. A hotfix typically…
4 min read

WeHow to Merge
use cookies a Git
to ensure Branch
you have the bestinto Master?
browsing experience on our website. By using our site, you
acknowledge that you have read and
If you're working with Git, merging branches understood our Cookie Policy & Privacy Policy
is a fundamental task.
Whether you're adding new features, fixing bugs, or improving…

https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 4/8
12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks
3 min read

How to Fix "master branch and 'origin/master' have diverged"?


When working with Git, you may encounter the "master branch and
'origin/master' have diverged" error. This message indicates that the loca…
3 min read

Git - Create a Branch From Another Branch


Branching in Git allows developers to work on isolated features or fixes
without affecting the main codebase. However, what if you need to creat…
3 min read

How to Make an Existing Git Branch Track a Remote Branch?


Managing branches in Git can sometimes be confusing, especially when
you need to make an existing local branch track a remote branch. This…
3 min read

How to Compare a Local Git Branch with its Remote Branch ?


When working with Git, it's often necessary to compare your local branch
with its remote counterpart to understand the differences in terms of…
3 min read

How to Create a Branch In Git from Another Branch?


Branching is a fundamental aspect of version control systems like Git,
which helps developers work on multiple features or bug fixes…
3 min read

Article Tags : Git Web Technologies

We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Corporate & Communications Address:-
A-143, 9th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 5/8
12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks
(201305) | Registered Address:- K 061,
Tower K, Gulshan Vivante Apartment,
Sector 137, Noida, Gautam Buddh
Nagar, Uttar Pradesh, 201305

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial

Data Science & ML Web Technologies


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning JavaScript
ML Maths TypeScript
Data Visualisation ReactJS
Pandas NextJS
NumPy NodeJs
NLP Bootstrap
Deep Learning Tailwind CSS

Python Tutorial Computer Science


Python Programming Examples GATE CS Notes
Django Tutorial
We use cookies to ensure Operating
you have the best browsing experience on our website. Systems
By using our site, you
Python
acknowledge Projects
that you have read and understood our Cookie PolicyComputer
& PrivacyNetwork
Policy
Python Tkinter Database Management System
Web Scraping Software Engineering
https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 6/8
12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks

OpenCV Tutorial Digital Logic Design


Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Commerce


Mathematics Accountancy
Physics Business Studies
Chemistry Economics
Biology Management
Social Science HR Management
English Grammar Finance
Income Tax

Databases Preparation Corner


SQL Company-Wise Recruitment Process
MYSQL Resume Templates
PostgreSQL Aptitude Preparation
PL/SQL Puzzles
MongoDB Company-Wise Preparation
Companies
Colleges

Competitive Exams More Tutorials


JEE Advanced Software Development
UGC NET Software Testing
UPSC Product Management
SSC CGL Project Management
SBI PO Linux
SBI Clerk Excel
IBPS PO All Cheat Sheets
IBPS Clerk Recent Articles

Free Online Tools Write & Earn


Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
We use cookies toCurrency
ensure Converter
you have the best browsing experience on our website.Internships
By using our site, you
acknowledge that you have
Random Number Generator read and understood our Cookie Policy & Privacy Policy
Random Password Generator

https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 7/8
12/8/24, 8:37 PM How To Get Changes From Master Into a Branch in Git? - GeeksforGeeks

DSA/Placements Development/Testing
DSA - Self Paced Course JavaScript Full Course
DSA in JavaScript - Self Paced Course React JS Course
DSA in Python - Self Paced React Native Course
C Programming Course Online - Learn C with Data Structures Django Web Development Course
Complete Interview Preparation Complete Bootstrap Course
Master Competitive Programming Full Stack Development - [LIVE]
Core CS Subject for Interview Preparation JAVA Backend Development - [LIVE]
Mastering System Design: LLD to HLD Complete Software Testing Course [LIVE]
Tech Interview 101 - From DSA to System Design [LIVE] Android Mastery with Kotlin [LIVE]
DSA to Development [HYBRID]
Placement Preparation Crash Course [LIVE]

Machine Learning/Data Science Programming Languages


Complete Machine Learning & Data Science Program - [LIVE] C Programming with Data Structures
Data Analytics Training using Excel, SQL, Python & PowerBI - C++ Programming Course
[LIVE] Java Programming Course
Data Science Training Program - [LIVE] Python Full Course
Mastering Generative AI and ChatGPT

Clouds/Devops GATE
DevOps Engineering GATE CS & IT Test Series - 2025
AWS Solutions Architect Certification GATE DA Test Series 2025
Salesforce Certified Administrator Course GATE CS & IT Course - 2025
GATE DA Course 2025

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy

https://www.geeksforgeeks.org/how-to-get-changes-from-master-into-a-branch-in-git/ 8/8

You might also like