Skip to content

Instantly share code, notes, and snippets.

@zerostyle
Forked from pr1ntr/git-commands.md
Created March 1, 2016 02:52
Show Gist options
  • Save zerostyle/459f28902e76f0f60884 to your computer and use it in GitHub Desktop.
Save zerostyle/459f28902e76f0f60884 to your computer and use it in GitHub Desktop.
stage all changedd files for a commit

git add .

stage specific file for a commit

git add /path/to/file

for some reason you want to unstage

git reset unstage all files
git reset /path/to/file unstage specific file

lets say you want to unstage something from previous commits

first
git log
find the commit hash you want

commit 93454a4218c704039cce719bd52e1d816a74047c   <-- THIS
Author: Pavel Zagoskin <d4rklit3@wildlife.la>
Date:   Mon Feb 29 18:10:38 2016 -0800

then reset it
git reset 93454a4218c704039cce719bd52e1d816a74047c
this will unstage all files in their changed form (in red) from your current HEAD all the way back to that commit. this is usefull for squashing commits. (if you have like 5 commits and you want them to be one commit).

lets say you want to just go back in time to a specific commit and not unstage anything. Just erase all your progress THIS IS DANGEROUS

git reset 93454a4218c704039cce719bd52e1d816a74047c --hard

make a commit with short message

git commit -m "the message"

make a commit with long message (opens up vi or whatever editor you set to git)

git commit

get all updated branches from origin (no merge)

git fetch

get status of current branch (do this after a fetch to see the comparison)

git status

if origin is ahead of your

git merge origin/$BRANCH_NAME

if you and origin are out of alignment.
ie, get this message on status:
Your branch and 'origin/develop' have diverged,
and have 1 and 2 different commit each, respectively.
this is where you rebase

git rebase origin/$BRANCH_NAME

push your up to date branch to origin

git push or git push origin $BRANCH_NAME

push your current most recent (HEAD) to some other origin branch (you don't need to specify origin/$BRANCH_NAME in this instance. other side of teh colon assumes its on origin)

git push origin HEAD:$OTHER_BRANCH_NAME
also you can just push any branch to any branch in origin
git push origin $ANY_BRANCH:$ANY_OTHER_BRANCH

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