On Git, to perform git fetch and git push with other project members, the “origin” and “master” repositories can be utilized. origin and master are two different terms used while working on and managing Git projects. More specifically, the origin is the default name assigned to a Git remote repository; however, the master is a Git branch name.
This blog will discuss the Git origin master branch.
How to Switch, Fetch and Push Origin Master?
To switch branches, fetch and push the local branch to remote; firstly, move to the Git root directory and create a new repository. Then, clone the repository and view the remote origin or list of the remote connections by executing the “$ git remote -v” command. Next, switch to the required branch.
Let’s move ahead and practically perform the above-specified procedure!
Step 1: Move to Git Root Directory
First, move to the Git root directory using the “cd” command:
Step 2: Create Repository
Run the “mkdir” command to create a new repository:
Step 3: Clone Repository
Clone the remote repository by utilizing the “git clone” command and specify the URL of the remote repository:
Step 4: Check Remote Origin
Run the “git remote” command to view the remote origin:
The given output displays the list of remote connections:
Step 5: Switch Branch
Next, switch to the master branch by utilizing the provided command:
Step 6: Fetch Branch
Now, download the remote master branch to the local repository using the “git fetch” command:
Step 7: Merge Remote Branch
Execute the “git merge” command to merge the local branch to the remote branch:
Step 8: Execute git push Command
Now, push the updated master branch to the remote repository through the following command:
We have explained about Git origin master with an example.
Conclusion
In Git, origin and master are two different terms. The origin is the default name assigned to a Git remote repository; however, the master is a Git branch name. To view the remote origin, execute the “$ git remote -v” command. Moreover, the “$ git checkout <branch-name>” command can be utilized to switch from one branch to another branch. This blog discussed Git origin master.