Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I git fetch/pull an outdated unchanged branch with one command?

Tags:

git

merge

fetch

Ok let's say we have a main branch called MAIN.

Let's say I create a local branch called 100.

Later on, someone creates a local branch on their own machine called 101.

Later on, they make changes to their local 101 branch, and then merge the changes back into MAIN.

Later on, I decide I'm finally ready to make some changes on 100.
However, I know MAIN has since changed. I want to make a one line git statement to update my local 100 branch with what's in MAIN.

Is there one?

Typically, I would do the following series of steps

git checkout MAIN
git pull
git checkout 100
git merge MAIN

How can I combine these series of steps into 1 command to pull the MAIN's branch into my local 100 branch (that contains no changes at the moment)?

like image 733
chris P Avatar asked Jan 22 '26 15:01

chris P


1 Answers

You can reduce the number of commands, but there are a series of distinct steps that you cannot skip, and which make no sense to combine:

  • select branch
  • fetch origin
  • merge changes

Git provides no magic single method for doing these three distinct and unrelated operations. The closest you're going to get is to either write your own higher-level command, or just do the three commands in one lin:

git checkout 100 && git fetch && git merge origin/MAIN
like image 109
meagar Avatar answered Jan 24 '26 08:01

meagar