Clone, fetch, pull & stash
Git - Quick Reference
2 min read
Published Jun 19 2025, updated Aug 17 2026
Guide Sections
Guide Comments
Cloning a repository
This is used to create a brand new project from an existing repository.
To create a copy of an existing repository:
git clone https://github.com/username/project.gitThis will clone the specified repository in to the current directory
To specify the directory:
git clone https://github.com/username/project.git newdirectorThis does the same but copies the files in to the specified named directory.
Fetching a repository
Get the latest commits from the remote repository, but don't merge them to the current branch:
git fetch originCurrent branch remains unchanged.
You can inspect the changes with git diff or git log.
Useful to see whats changed before pulling.
Pulling a repository
Fetch and merge into the current branch:
git pull origin mainFetches changes from the origin/main and merges them in to the current branch. May cause merge conflicts.
Pull and apply local commits:
git pull --rebaseWill add your local commits on top of the remote ones to give a cleaner history.
Stashing
Temporarily shelve or stash your changes that are not committed, so you can work on something else, and bring them back later:
git stashStashes changes in tracked files and clears them from the working directory.
You can then safely checkout another branch, do your work, then to go back to what you were doing:
git stash popWhich applies the most recent stash and removes it from the stash list.
To keep bring back a stash but also keep it in the stash list:
git stash applyTo stash everything, including untracked changes:
git stash -uTo list all stashes:
git stash listTo show the most recent stash:
git stash showTo apply a specific stash from the list:
git stash apply stash@{1}To delete a specific stash:
git stash drop stash@{1}To delete all your stashes:
git stash clear