Skip to content

Instantly share code, notes, and snippets.

@bulkan
Last active December 14, 2015 06:39
Show Gist options
  • Save bulkan/5044456 to your computer and use it in GitHub Desktop.
Save bulkan/5044456 to your computer and use it in GitHub Desktop.

how to do things in git

interactive adding of hunks

git add -p <filename>

add upstream original repo

git remote add upstream <upstream git url>

##Undo a commit

git reset --soft HEAD^

merge upstream changes

git fetch upstream

merge upstream branch into a local branch

git checkout <branch>

# the following will create a merge commit
git merge upstream/master --no-ff  

# rebase
git rebase upstream/master

accept theirs

git pull --rebase -s recursive -X ours

Creating Pull Requests

create a local branch

git checkout master
git checkout -b <branch_name>

add some commits then push

push -u origin <branch_name>

Move a dir/file from one repo with it's history to another

git remote add other /path/to/XXX
git fetch other
git checkout -b ZZZ other/master
mkdir ZZZ
git mv stuff ZZZ/stuff             # as necessary
git commit -m "Moved stuff to ZZZ"
git checkout master                
git merge ZZZ                      # should add ZZZ/ to master
git commit
git remote rm other
git branch -d ZZZ                  # to get rid of the extra branch before pushing
git push                           # if you have a remote, that is

removing master branch

git branch placeholder
git checkout -b placeholder   
git branch -D master
  • On github change default branch to placeholder and delete the master branch
  • Delete the repo and reclone it ? Not sure if this step is necessary
git checkout -b master
git push origin master
  • Change default branch on github to master again
git branch -D placeholder

Tags

git tag -a 1.2.3 -m 'version 1.2.3'
git push --tags

Search commits

git grep <regexp>

git log -G <regexp>

Revert a commit

git revert <sha>

This will create a new commit with a diff reversing the commit referred by

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