Git Command to Get the Latest Code From Master

By | September 22, 2020

Here is the basic reference to Git with introduction with example and answer to get latest code from master branch in git.

Git Command to Get the Latest Code From Master
Git Command to Get the Latest Code From Master

Introduction

What is Git?

Git: Git is a distributed version control system which is used by developer all over the world.

Git is designed for manage small to large projects with speed and efficiency.

What is the meaning of version control ?

Here is the one-line answer, the meaning is your local copy of the project source code is a complete version control repository. This is helpful for working remotely and in offline mode.

Git Command to Get the Latest Code From Master

Case 1: If you don’t care about local modification

Solution 1: Get the latest code and reset the code

Solution 2: Delete the folder and clone again

Case 2: Care about local changes

Solution 1: No conflicts with new-online version

will report something like:

Your branch is behind ‘origin/master’ by 1 commit and can be fast-forwarded.
Then get the latest version

git pull


Solution 2: Conflicts with the new-online version

git fetch origin
git status

will report something like:

error: Your local changes to the following files would be overwritten by merge:
file_name
Please, commit your changes or stash them before you can merge.
Aborting
Commit your local changes

git add .
git commit -m ‘Commit msg’

Try to get the changes (will fail)

git pull


will report something like:

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use ‘git add/rm ‘
as appropriate to mark resolution, or use ‘git commit -a’.
Open the conflict file and fix the conflict. Then:

git add .
git commit -m ‘Fix conflicts’
git pull


will report something like:

Already up-to-date.

Here is your solution to get updated with the master branch using git Bash commands.

Know more: https://git-scm.com/

Also check:

Happy Coding..!

Subscribe For Latest Updates

Sign up to best of PHP Code Solutions, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *