Skip to content

Instantly share code, notes, and snippets.

@laszlomiklosik
Last active October 11, 2015 23:08
Show Gist options
  • Save laszlomiklosik/3934095 to your computer and use it in GitHub Desktop.
Save laszlomiklosik/3934095 to your computer and use it in GitHub Desktop.
Git utils
# select one of the 2 file versions during a merge
git checkout --ours index.html
git checkout --theirs _layouts/default.html
# see history in a nice tree form without gitk
git log --pretty=oneline --graph --decorate --all
# git add all including the renamed files without loosing history of the deleted file (as a rename implicitly looks like delete file and create new file)
git add . -A
# search all tracked files by content
git grep aPattern
# push a new branch to upstream
# make sure you are on the new branch locally
git push -u origin your_branch
# create a branch and check it out in the same command
git checkout -b newbranch
# create a branch from an old commit (I should have created a branch yesterday situation!)
git checkout HEAD^^^
or
git checkout HEAD~3
or
git checkout aSha1CommitHash
and this will tell you that you are in a detached head state, but can start a branch from there using:
git checkout -b new_branch_name
# check incoming upstream changes before merging them in
git fetch
git diff local_branch_name origin/remote_branch_name
after that you can:
git merge
# reset my local branch to the same state as on remote:
git fetch origin
git reset --hard origin/branch_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment