I am confused how to use Shall and Can. For example:
Shall I commit the code
Can I commit the code
Which one of the above is correct?
Each is correct in different contexts. It's not a question of "one is right and one is wrong".
"Shall I do X?"
is an inquiry as to whether something ought to be done. You could safely rephrase it as "Do you want me to do X?" The underlying question is "Would it be a good thing for me to do X?"
"Can I do X"
taken literally, is a question as to whether the one asking is capable of doing X. You could alternatively put it as "Am I capable of doing X?"
However, "Can I do X?" is often casually used in place of
"May I do X?"
Which would be safely rephrased as "Am I permitted/allowed to do X?" This distinction between "Can I" and "May I" can be seen in
"Yes, of course you can [are physically able to] eat all the cookies in the jar, but you may not [you are not permitted to do so]."