-
Notifications
You must be signed in to change notification settings - Fork 3
Git
Ignore changes in a submodule. Add ignore = all
# open .gitmodules
[submodule "my_module"]
path = my_module
url = git@github.com:example/my_module.git
ignore = all--
Checkout individual file one commit behind.
git checkout HEAD^1 android/adb.js
Two commits behind.
git checkout HEAD~2 android/adb.js
--
Rebase upstream master onto local master.
git pull --rebase up master--
Update submodules.
git submodule foreach git pull origin master--
Reset author to yourself.
git commit --amend --reset-authorReset author to someone else.
git commit --amend --author "username <example@example.com>"--
Rename tag v0.0.9 to v0.0.09.
git tag v0.0.09 v0.0.9
git tag -d v0.0.9
git push origin v0.0.09
git push origin :v0.0.9--
Fix deleted file not staged.
git add -u
--
Reset local branch with remote.
git remote add b git@github.com:bootstraponline/appium.git
git fetch b
git reset --hard b/reconnect
--
$ git --version
git version 1.8.1.4
--
Disable blinking cursor in MacVIM.
:set gcr=a:blinkon0
--
Push local master to remote clean branch.
git push origin master:clean
--
Rename patch-1 branch for pull request and delete the old branch.
git fetch origin patch-1
git checkout patch-1
git branch -m patch-1 reset_android
git push origin reset_android
git push origin :patch-1--
Delete a bunch of remote branches.
$ git branch --remote
b = %(origin/branch1
origin/branch2
)
b.each_line { |l| puts 'git push origin :' + l.strip.chomp + ";\\ \n" }--
Update date from StackOverflow
GIT_COMMITTER_DATE="`date`" git commit --amend --date "`date`"
--
Don't push to all branches by default.
git config --global push.default simple
git branch --set-upstream master origin/master
Text width in vim (wraps on space) ~/.vimrc
:set tw=80
:set formatoptions=tcq
Stop ruby.
killall -v ruby -s SIGKILL
Cherry pick one commit from a pull request.
git remote add pr git://github.com/npisenti/gollum.git
git fetch pr
git cherry-pick ba8dd5e4bca08efa7b73987a266f74a12ca3fe5c
# we could also checkout pr
git checkout pr/master
git config --global branch.autosetuprebase always
List all tags, create a lightweight tag, show a tag, then push to origin.
git tag
git tag v1.0
git show v1.0
git push origin v1.0
Fix confused git pull.
git config branch.master.remote origin; \
git config branch.master.merge refs/heads/master;
git config --global core.editor "gedit -w -s"
Redo a commit before it has been pushed.
git reset --soft HEAD^1
Revert a failed merge.
git revert -m 1 20dd0816a6
Stash current changes, delete last 3 commits, and then commit current changes.
git stash
git reset --hard HEAD~3
git stash pop
Add only empty files to a commit:
git ls-files --deleted | xargs git rm
Create empty branch java:
git symbolic-ref HEAD refs/heads/java
Squash commits in a pull request.
# Squash the 3 most recent commits.
# Change 'pick, pick, pick' to 'pick, s, s'
# or use f to discard the commit message
# Ctrl + \ in nano will open search and replace (pick -> s)
git rebase -i HEAD~3
git push --force
http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
Save current changes, pull from upstream, restore changes, and clear the stash.
git stash save
git pull
git stash pop
git stash clear
How to revert a failing pull request:
git revert --no-edit -m 1 HEAD
Updating submodules.
git submodule update --init
Amending.
git commit --amend -m "New msg."
Override branches for clean history in pull requests. Example overrides try1 with try2. Push using git push -f origin try1.
# git branch => on try2
git branch -f try1
Rebase to update an upstream branch on a local fork.
git remote add upstream git://github.com/github/gollum.git
git fetch upstream
git rebase upstream/master
Commands and descriptions based on Quicksilver's workflow.
-
Fork
https://github.com/github/gollumby clicking the Fork button. -
Clone your fork.
git clone git@github.com:bootstraponline/gollum.git
cd gollum -
Add upstream.
git remote add upstream git@github.com:github/gollum.git -
Rebase master branch to upstream as upstream changes.
git pull --rebase upstream master -
Create new branches from master for each work item.
git checkout -b workBranch master -
Commit work to the branch.
git add .
git commit -am "Add feature." -
Rebase branches to master.
git checkout workBranch
git rebase master -
Push branch to github.
git push origin workBranch
Orgit pushif the branch is already checked out. Note that git push will push all branches, including master. -
Submit pull requests from branches and delete when no longer needed.
Note that GitHub will not allow deleting master branch if it's set as default.
git push origin :workBranch
git branch -D workBranch
Useful commands:
git reset --hard
git push --force
git branch
From git's documentation:
In other words, "git push --force" is a method reserved for a case where you do mean to lose history.
Create a new branch based on upstream.
git remote add upstream https://github.com/github/gollum.git
git fetch upstream
git checkout -b newBranch upstream/master
git clean -dn
Force clean:
git clean -df
git config --global color.ui "auto"
git config --global alias.lg "log --graph --decorate --oneline"
Command from sant0sk1
git lg
Set name and email.
git config --global user.email "spam@email"
git config --global user.name "my name"