Clone, fetch, pull & stash

Git - Quick Reference

2 min read

Published Jun 19 2025


7
0
0
0

CLIGit

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.git

This will clone the specified repository in to the current directory


To specify the directory:

git clone https://github.com/username/project.git newdirector

This 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 origin

Current 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 main

Fetches changes from the origin/main and merges them in to the current branch. May cause merge conflicts.


Pull and apply local commits:

git pull --rebase

Will 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 stash

Stashes 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 pop

Which 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 apply

To stash everything, including untracked changes:

git stash -u

To list all stashes:

git stash list

To show the most recent stash:

git stash show

To 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


Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact