Your branch is behind ‘origin/main’ by 2 commits, and can be fast-forwarded

Did you switch to main branch after doing development on some other branch for sometime ? And did you notice git status showing message “Your branch is behind ‘origin/main’ by 2 commits, and can be fast-forwarded“. This sneppet will guide you how your branch can be fast-forwarded.

What’s the state of working directory

The following git command displays the state of your working directory and stage area. It actually displays what are the changes that have been staged and what’s that not staged. Also, it displays which files are not tracked by Git.

$ git status 

On branch main Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded. 
  (use "git pull" to update your local branch)

nothing to commit, working tree clean

Let’s say the local working directory file1.txt content looks like:

first line
second line
third line

But, in Git main branch the content of file1.txt looks like below:

first line 
second line 
third line 
fourth line

git pull command to fast forward your local branch

Now, your branch can be fast forwarded to include or update the changes from Git to your local working directory using the following git command.

The git pull command used to fetch and download the content from a remote Git repository and immediately update the local branch repo to match the exact same content.

$ git pull origin

Updating 774e727..ef8115c
Fast-forward
 file1.txt | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

After running git pull origin command, check the contents of the file1.txt in the local working directory. You should see file1.txt is updated with same changes as in Git.

first line
second line
third line
fourth line

Finally, try git status command to check if your branch if fast forwarded. Now, you should see a message showing “your branch is up to date with ‘origin/main”

$ git status

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

That’s it. Hope you find this sneppet helpful 🙂

You’ll Also Like

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments