Now let’s look at one of typical real life scenarios.
You came to the office in the morning and you want to get all latest changes:
this would sync your copy with other repository. If you want merge it manually you can do
Let’s say you want to work on a new feature, good idea would be create a branch and work in this branch:
git checkout -b "feature_name"
At the end of the day (or before you go to lunch) you would want to save your work. You tell git of the files you want to save (you stage it):
git add file_names...
or add all updated files
git add -u
then save them
git commit -m "some comments"
optional, save your changes on the server as well
If you stuck and want to start all over (without saving anything!) you can call reset:
git reset --hard
Once the feature is done, you want to merge it to the main branch:
– switch to the main branch
git checkout master
– update it
– and merge
git merge "feature_name"
if you during the course of feature implementation you did multiple commits you don’t want all of them appear in the master branch history. You want it to be visible as one commit only, so you squash it:
git merge "feature_name" --squash
If you get conflict errors, you need to edit all the files with conflict (git would list them to you), then save them:
git add "conflict_file" git commit -m "Merge master"
To get the picture of git status – current branch name, which files had been changes locally, which commits had not been pushed you run
To get the picture of all commits:
To see what changes had been done to local files:
To see the picture of all branches: