Git commands frequently used - Cidana-Developers/Cidana-Task-Manager GitHub Wiki

How to create a local branch and track from remote

$: git pull # update to the latest
$: git checkout -b new_branch # create new_branch and switch to new_branch
$: git push origin new_branch:new_branch # setup new_branch at remote.
$: git branch --set-upstream-to=origin/new_branch new_branch # track with new_branch at remote

After this, we can simply git commit and git push to publish your CL.

How to modify your last commit

If you haven't pushed it to remote, it will be very simple:

$: git add modified_files
$: git commit --amend
$: git push

If you already pushed to remote, now it will report " Your branch and 'origin/test_api' have diverged, and have 1 and 1 different commits each, respectively.". We need force-push now:

$: git push -f

Usually, force-push is not recommended, but it is fine in this case since you only modify this branch.

Squash commit

Usually, you should use git commit --amend to modify your previous change, but if you already submited several minor changes, we should squash commit then push to remote. Please refer to amend a commit on a github pull request

Generally, we should keep our commit history clean and meaningful.