Skip to content

Instantly share code, notes, and snippets.

@sankars
Created April 23, 2014 18:00
Show Gist options
  • Select an option

  • Save sankars/11226248 to your computer and use it in GitHub Desktop.

Select an option

Save sankars/11226248 to your computer and use it in GitHub Desktop.
## create a local repo and commit it to github account
## http://stackoverflow.com/questions/2423777/is-it-possible-to-create-a-remote-repo-on-github-from-the-cli-without-ssh
mkdir projectname
cd projectname
git init
touch file1
git add -n . ## do a dry run
git add file1
git commit -m 'first commit'
git remote add origin git@github.com:USER/REPO.git
git push origin master
## http://stackoverflow.com/questions/1028649/rename-a-tag-in-git
git tag new_tag old_tag ## create an alias to the old_tag
git tag -d old_tag ## delete the old tag
## http://stackoverflow.com/questions/61212/removing-untracked-files-from-your-git-working-copy
git clean -n ## preview changes before remove
git clean -f ## removes files. changes unrecoverable
git clean -f -d ## removes directories and files
git clean -f -X ## removes ignored files only
git clean -f -x ## removes ignored files and untracked files
git clean -i ## removes but interactive
## http://stackoverflow.com/questions/4089430/how-can-i-determine-the-url-that-a-local-git-repo-was-originally-cloned-from
git config --get remote.origin.url
git remote show origin
git remote -v ## print all push/pull URLs
## http://stackoverflow.com/questions/179123/edit-an-incorrect-commit-message-in-git
git commit --amend -m "New commit message"
# http://stackoverflow.com/questions/3471827/how-do-i-list-all-remote-branches-in-git-1-7
git ls-remote --heads <remote-name> ## e.g remote-name = origin
git ls-remote <url> ## without cloning
git branch -a
git branch -r
git remote show <remote-name>
## delete & restore working dir from git db.From Git Recipes
rm -R .
git reset --hard
## clone a bare repo
git clone --bare repo_name
## git repo statistics
git log --oneline | wc -l ## Total commits
git shortlog -s | wc -l ## Total contributors
git ls-files | wc -l ## Total files in repos
## git reset
git reset --hard ## restore working directory from git db. Will lose changes in working dir
git reset -- filename ## to unstage a file
## git config
git config --global alias.l "log --oneline" ## set an alias
git config --global -l ## print all configs
git config --global --get-regex alias ## print all aliases
git config --global --get user.name
git config --global --unset alias.l
## http://stackoverflow.com/questions/14075581/git-undo-all-uncommited-changes
## undo local changes and go to clean state
git reset
git checkout .
git clean -fdx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment