# Git Best Practices for working with AI Coding Agents

0. Reminder: How git works, branches and commits


[Point in time]     [P2]      [P3]     
     #1             #2         #3      

    Commit           Commit    Commit  
                     [main] 
------------------------------------------------


/resume      ===> branch
<esc> <esc>  ===> reset --hard
cancel       ===> git restore . && git clean -f -d


------------------------------------------------


1. commit often, rebase when ready
    - after every AI turn -> commit
    - cancel commit - git reset --hard
    - commit --amend
    - commit - commit - commit  => git reset --hard <commit>
    - commit - commit - commit - commit => git rebase -i
    - feature => branch (worktree)
    - feature => branch (worktree)


2. restore && clean
    - https://www.tocode.co.il/blog/2026-01-git-skip-worktree

3. fixing commits
    - commit --amend
    - reset --hard HEAD~

4. worktree
    - create multiple worktrees
    - run multiple coding agents in parallel

5. git diff feature...main
    - https://www.tocode.co.il/blog/2026-02-two-vs-three-dot-git-diff

6. What can go wrong?
    - Shared resources: DB, port, filesystem
    - Coding agents are terrible at refactoring

7. Q & A

https://www.dbreunig.com/2026/05/04/10-lessons-for-agentic-coding.html
