Git Commands – Help Sheet

Essential Git commands for effective software development.

Undo a commit

git reset HEAD —hard

Pulls latest changes from the repo and rebases changes from the master branch

git pull origin remote-branch —rebase master


git reset –soft HEAD

Resets stage locally (undo’s any uncommitted changes)

git reset -—hard HEAD

Continues iterating through merged changes made from the rebased repo

git rebase —continue

Aborts merging rebased changes

git rebase —abort

Force pushes changes made to the local repo (usually made when a rebase has occurred when updating a branch)

git push origin branch —force

Fetches all remote branch names not in local

git fetch

Checks out a remote branch into local tracking that repo for changes

git checkout —track remote-branch

Create a new branch and switch to it

git checkout -b branch

Current local branch

git branch -l

List current, all local remote branches being tracked

git branch -a

Display URL to remote repository

git remote -v

Add New Repository URL

git remote add origin url

Change Existing Repository URL

git remote set-url origin repository-url

Delete a local branch

git branch -D branch

Delete a remote branch

git push origin –delete remote-branch

Stages a file for commit

git add path-to-file

Commits all staged files with commit message

git commit -am “message”

Stash Changes

git stash

List Stash Changes

git stash list

Apply Stash

git stash apply stash@{stashIndex}

Note: 0 is the most recent stash

Delete Stash by Index

git stash drop stash@{stashIndex}

Delete All Stashes

git stash clear

This will delete ALL your stashed changes

This entry was posted in Software Engineering, Version Control. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>