Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
Git - Origin Master
Next article icon

Git - Origin Master

Last Updated : 23 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Git is a popular version control system used by developers to manage and track changes in their code. Among the many concepts in Git, git origin master is fundamental, especially for those who are new to Git or looking to understand best practices for managing repositories. In this article, we’ll break down what git origin master means, how to use it, and why it’s important for your development workflow.

What is git origin master?

In Git, origin and master are two critical terms that you'll encounter frequently:

  • Origin: This is the default name given to the remote repository from which you cloned your local repository. It acts as a shorthand reference for the URL of your remote repository.
  • Master: This is the default name for the main branch in your repository. In many projects, this branch contains the stable and production-ready version of the code.

Git - Origin

Let's see how Origin and Master are used in Git projects. Origin in simple words means from where something is originated or derived.

  • Origin is simply the name given to any remote repository available on GitHub.
  • Whenever we need to push the changes to a remote repository, we use git push along with the remote repository "origin" and "master" branches. The term used is "git push origin master".
  • To pull the changes from the remote repository to local, we use git pull along with remote repository "origin" and "master" branch. The term used is "git pull origin master".

When cloning the remote repository to local, we use "git clone" command  and pass the URL for the remote repository as below

The "git remote" command is used to show the remotes mapped to git remote repository

Git remote -v: Shows all the remote connections linked to a git repository. It shows fetch and push operations on a remote repository as below

Git - Master

Master is the name of a default branch in git terminology. Whenever a new repository is created in git, git gives the default name to a branch as 'Master'.

  • When a new repository is initialized using "git init" command, git creates a single branch by default such as the "Master" branch.
  • When multiple developers collaborate on a single feature/development work, developers create a pull request to merge the changes to master branch. After the review is done by the senior developer, changes are merged to the master branch.
  • The Master branch is the most up-to-date branch and has production-ready code.

Now, let's initialize a new git repository using the "git init" command as follows:

Now run the "Git Branch" command and check that we have a single branch in a remote repository which is 'main' or 'master' branch as below:

Check the Github page and see that there is the only branch, i.e the main branch as below depicted as follows:

Origin/Main in Git

Since Origin and Master are two different terminologies in Git but we might get confused when we see Origin/master in git context

  • Origin/master is a remote-tracking branch.
  • This branch exists in our local and tracks the remote repository 'origin' and branch 'master'.
  • Branch in format "remote-name/remote-branch-name" is a remote-tracking branch

Since origin/master is a branch. Below is the process to merge the origin/master to master branch on remote origin

Step 1: Fetch the remote branch 'master' from remote 'origin'. Master branch would be fetched to local and local copy would be called as origin/master

git fetch origin master

Step 2: Then merge the 'origin/master' to 'master'

git merge origin/master

Step 3: Finally, now push the changes from remote branch 'master' to remote 'origin'

git push origin master

Best Practices for Using git origin master

  1. Keep master Stable: Ensure that the master branch always contains stable and production-ready code.
  2. Regular Pulls: Frequently pull changes from origin master to keep your local repository up-to-date.
  3. Use Branches: Work on features and fixes in separate branches, and merge them into master only when they’re ready.

Next Article
Git - Origin Master

D

deepeshnagpal
Improve
Article Tags :
  • Web Technologies
  • Git
  • Geeks Premier League
  • Geeks-Premier-League-2022

Similar Reads

    What is "origin" in Git?
    When working with Git, especially in collaboration with others, you will often encounter the term "origin." Understanding what "origin" means and how it functions within Git’s workflow is important for effective source code management. In this article, we will walk you through everything you need to
    4 min read
    Git Tutorial
    Git is an essential tool for developers, enabling them to manage and track project changes. Whether you're working on a solo project or collaborating with a team, Git keeps everything organized and under control. This Git Tutorial, from beginner to advanced, will give you a complete understanding of
    12 min read
    Working With Git Repositories
    Git is a powerful and widely-used version control system that helps developers manage their codebases efficiently. By using Git repositories, developers can track changes, collaborate with others, and maintain a history of their project’s development. In this article, we will learn about working wit
    7 min read
    Git Security Model
    Git is one of the most popular version control systems, used by developers and non-developers for tracking changes, collaborating on projects, and managing codebases. While Git is popular for its efficiency in handling version control, its security features are equally robust, ensuring that your cod
    7 min read
    How to Login to Git?
    Git is a popular version control system used by developers to manage code and collaborate on projects. To fully utilize Git’s features, you need to log in, which involves setting up authentication with a Git hosting service like GitHub, GitLab, or Bitbucket. In this article, we’ll guide you through
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@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
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences