Skip to content

Instantly share code, notes, and snippets.

Last active June 8, 2021 21:39
Show Gist options
  • Save abadongutierrez/9920732 to your computer and use it in GitHub Desktop.
Save abadongutierrez/9920732 to your computer and use it in GitHub Desktop.
Useful git commands

Getting logs


Show staged and not staged but no untracked files

git status -uno


Checkout remote branch with the same name and tracking it

git checkout --track origin/<branc-name>

Delete branch (because you dont use it anymore)

Delete the branch locally:

git branch -d <branch-name>

Feature Branch Workflow

Create the branch locally:

git checkout -b <branch-name>

Create the branch remotely:

git push -u origin <branch-name>

Create/Modify/Add/commit/push normally.

When ready to merge to master, go to master and:

git merge <branch-name> --squash --no-commit

The option --squash put together all the commits from the branch and creates just one commit. And the option --no-commit dont apply the commit so you can review the changes.

Delete the local branch and the remote branch:

git branch -d <branch-name>

git push origin :<branch-name>


On master:

git pull

On the branch:

git merge master

Resolve conflicts if any and commit/push.

Getting info

Get log since 2 weeks

git log --since=2.weeks --author=jlara

Get log since specific date

git log --since="2014-03-18" --author=jlara --all-match

Get log since 3 weeks for both authors

git log --since=3.weeks --author=jlara --author=rgutierrez --all-match
git log --author="rgutierrez" --pretty=format:"%h - %an, %ar : %s" --since=3.months 

Complete Hash

git log --author="rgutierrez" --pretty=format:"%H - %an, %ar : %s" --since=3.months 

Cherry Picking

Cherry pick without commit

git cherry-pick --no-commit <hash>

Cherry pick commiting changes

git cherry-pick -x <hash>


Clean untracked files:

git clean -f -d

Branch Managment

Delete a branch locally:

git branch -d the_local_branch

Delete a branch remotelly:

git push origin :the_remote_branch

Remove any remote-tracking branches which no longer exist on the remote:

git fetch -p

Looking at the history

Diff between commits

git diff hash1 hash2

Diff between commits (but just one file)

git diff hash1 hash2 <path-to-file>

What are the changes in commit?

git show hash

What are the files that changed in commit?

git show hash --name-only

Undoing work

To reset your local to an specific hash in a "HARD" way. That means destroying any local modification.

git reset --hard <hash>

Do not do this if you have uncommited work that you want to keep.


git stash
git stash pop
git stash list
git stash show -p
git stash show -p stash@{4}
Copy link

imarban commented Jan 18, 2016

You are the third result in Google when looking for watering in git 👍

Copy link

Yep, imarban is right, you're a rockstar

Copy link

I didnt notice, thanks!

Copy link

first result now! Marry me Rafa <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment