Well, regardless of how you do it you'd definitely need the task ID (as you pointed out, it's in the URL). What we actually do internally is just paste a link to an Asana task - it contains the ID, identified it as an asana task, and is clickable in many views so you can jump right to the task it's talking about when viewing commit history. Very handy!
We then have what is essentially a commit hook look for https://app.asana.com/..., grab the task ID and post a new comment linking to the commit in our source control and the commit message.
Using URLs means the link goes both ways, which is incredibly convenient.