Git Crash Course - odoo-ps/pshk-process GitHub Wiki

Git Crash Course

Here are some common useful git commands during development


Cloning

git clone {ssh:link}

Use SSH for cloning since some repositories may only be accesses using SSH cloning.


Add, Commit, Push

git add {files_to_include}
git add . # to automatically add everything

git commit -m "{commit_message}"
git commit # to open it in interactive mode

git push {remote} {branch}
git push origin 14.0-lpj # example
git push origin HEAD # HEAD to refer to current branch

Squash Commits

Often when pushing to staging/production branch, you keep it at 1 commit per task.

git rebase -i HEAD~{num_commit_to_squash}
# use fixup to squash

git_1 git_2 git_3 git_4

Rewrite History

The same way you squash commit, you can also Rewrite the history of your commits using rebase

git rebase -i HEAD~{num_of_commit}

git_5 git_6 git_7 git_8

To delete commit, use "d" on the interactive rebase (instead of "f' for fixup).

However, it's very important to keep note that rewriting history is quite costly ESPECIALLY if some of your commits have been pushed to remote repository.


Cherry-pick

In instances where you want to adopt a commit from another branch, you can use cherry-pick.

A big use of this is usually in SH where you want to change the code you push to staging branch.

What you would usually do is delete the commit you made for the particular task and then cherry pick a new one.

git cherry-pick {commit_id}

To get commit id you can do tig and click Enter on the specific commit you want git_9