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


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:
Please, commit your changes or stash them before you can merge.
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:

Also check:

Happy Coding..!

Was this article helpful?

By Bikash

My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.

Leave a Reply

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