Here is the basic reference to Git with introduction with example and answer to get latest code from master branch in git.
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
1 2 |
git fetch origin git reset --hard origin/[tag/branch/commit-id usually: master] |
Solution 2: Delete the folder and clone again
1 2 |
rm -rf [project_folder] git clone [remote_repo] |
Case 2: Care about local changes
Solution 1: No conflicts with new-online version
1 2 |
git fetch origin git status |
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:
- Display Current Date and Time in HTML using JavaScript
- Learn How to JavaScript Append HTML to Body
- Create Date Picker using Materialize Framework
- PHP Venmo Integration with Braintree
Happy Coding..!