Skip to content

Instantly share code, notes, and snippets.

@jesperhj
Last active December 1, 2015 16:39
Show Gist options
  • Save jesperhj/3076444 to your computer and use it in GitHub Desktop.
Save jesperhj/3076444 to your computer and use it in GitHub Desktop.
Git
List remote and local branches
git branch -a
List only remote branches
git branch -r
Create new branch
git checkout -b newbranch
Create a local test branch which is tracking the remote test branch.
git branch test origin/test
Push branch to origin
git push origin newbranch
Push all branches
git push origin
Export git repo
git archive master | tar -x -C /somewhere/else
Delete a local branch
git branch -D bugfix
Locally and Remotely Renaming a Branch in Git
http://www.benjaminlhaas.com/blog/locally-and-remotely-renaming-branch-git
Splitting a subpath out into a new repo
# Clone the repo we're going to work with
git clone git://github.com/defunkt/github-gem.git
# Change directory into the repo
cd github-gem/
# Filter the master branch to the lib path and remove empty commits
git filter-branch --prune-empty --subdirectory-filter lib master
# Change the [remote "origin"] url property in the .git/config file to point to the new repository
emacs .git/config
# Push code to origin
git push -u origin master
# Rebasing an old commit
http://christoph.ruegg.name/blog/2010/5/5/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html
# Add new, modified and deleted files
git add -A stages All
git add . stages new and modified, without deleted
git add -u stages modified and deleted, without new
# Delete untracked local files from your current branch
# Show what will be deleted with the -n option
git clean -f -n
# Then - beware: this will delete files - run:
git clean -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment