Skip to main content

Git cheat sheet

Below is a quick cheat sheet for translating a number of Git commands into equivalent Sapling commands.

You can also use the sl githelp command, or sl git for short, to automatically translate some git commands into their equivalent Sapling command.

$ sl githelp -- git clone https://github.com/facebook/sapling
sl clone https://github.com/facebook/sapling

$ sl git -- checkout 060f340a9 my_file.txt
sl revert -r 060f340a9 my_file.txt

Cloning, pulling, and pushing

GitSapling
Clonegit clone http://github.com/foo my_reposl clone http://github.com/foo my_repo
Pullgit fetchsl pull
Pull a branchgit fetch origin REFSPECsl pull -B BRANCH
Pull and rebasegit pull --rebasesl pull --rebase
Push to a branchgit push HEAD:BRANCHsl push --to BRANCH
Add a remotegit remote add REMOTE URLsl path --add REMOTE URL
Pull from a remotegit fetch REMOTEsl pull REMOTE

Sapling only clones and pulls a subset of remote branches.

Understanding the repository

GitSapling
Your commitsN/Asl
Current historygit logsl log
Edited filesgit statussl status
Current hashgit rev-parse HEADsl whereami
Pending changesgit diffsl diff
Current commitgit showsl show

Referring to commits

GitSapling
Current commitHEAD.
Parent commitHEAD^.^
All local commitsN/Adraft()
Commits in branch X but not YY..XX % Y

See sl help revset for more ways of referencing commits.

Working with files

GitSapling
Add new filegit add FILEsl add FILE
Un-add new Filegit rm --cached FILEsl forget FILE
Remove filegit rm FILEsl rm FILE
Rename filegit mv OLD NEWsl mv OLD NEW
Copy filecp OLD NEWsl cp OLD NEW
Add/remove all filesgit add -A .sl addremove
Undo changesgit checkout -- FILEsl revert FILE
Undo all changesgit reset --hardsl revert --all
Delete untracked filesgit clean -fsl clean
Output file contentgit cat-file -p COMMIT:FILEsl cat -r COMMIT FILE
Show blamegit blame FILEsl blame FILE

Working with commits

GitSapling
Commit changesgit commit -asl commit
Modify commitgit commit -a --amendsl amend
Move to commitgit checkout COMMITsl goto COMMIT
Remove current commitgit reset --hard HEAD^sl hide .
Edit messagegit commit --amendsl metaedit
Rebase commitsgit rebase mainsl rebase -d main
Complex rebasegit rebase --onto DEST BOTTOM^ TOPsl rebase -d DEST -r BOTTOM::TOP
Rebase allN/Asl rebase -d main -r 'draft()'
Interactive rebasegit rebase -isl histedit
Interactive commitgit add -psl commit -i / sl amend -i
Cherry-pickgit cherry-pick COMMITsl graft COMMIT
Stash changesgit stashsl shelve
Unstash changesgit stash popsl unshelve

Undo, redo, and reverting

GitSapling
Undo commitgit reset --soft HEAD^sl uncommit
Undo partial commitgit reset --soft HEAD^ FILEsl uncommit FILE
Undo amendgit reset HEAD@{1}sl unamend
Undo rebase/etcgit reset --hard HEAD@{1}sl undo
Revert already landed commitgit revert COMMITsl backout COMMIT
View recent commitsgit reflogsl journal
Recover commitgit reset COMMITsl unhide COMMIT

Working with stacks

GitSapling
Modify middle commitgit rebase -isl goto COMMIT && sl amend
Move up/down the stackgit rebase -isl prev / sl next
Squash last two commitsgit reset --soft HEAD^ && git commit --amendsl fold --from .^
Split a commit into twoN/Asl split
Reorder commitsgit rebase -isl histedit
Amend down into stackN/Asl absorb

Giving commits names

GitSapling
Listing branchesgit branchsl bookmark
Create branch/bookmarkgit branch NAMEsl book NAME
Switch to branchgit checkout NAMEsl goto NAME
Delete a branchgit branch -d NAMEsl book -d NAME (deletes just the bookmark name) / sl book -D NAME (deletes the bookmark name and hides the commits)

Resolving conflicts

GitSapling
List unresolved conflictsgit diff --name-only --diff-filter=Usl resolve --list
Mark a file resolvedgit add FILEsl resolve -m FILE