git config credential.helper store
git update-ref -d HEAD
git reset --soft HEAD~n
git shortlog -s -n --all
git push origin +{commit-id}^:master
git remote -v
git commit --date "date-format" -m "commit message"
git show-branch
git tag
git config -l
git reset <file_name>
git reset <folder_name>/
git diff --staged
git remote set-url <remote_name> <url>
git update-index --assume-unchanged <file>
another alternative :
git update-index --skip-worktree <file>
more information on difference between assume-unchanged and skip-worktree.
git update-index --assume-unchanged <folder_name>/
git update-index --no-assume-unchanged [<file> ...]
git tag --sort=-creatordate
git tag --delete tagname
git push --delete origin tagname
First, clone the remote repository :
git clone "remote repository url"
Then, see what branches exist in this repository
git branch -a
If you just want to take a quick peek at an upstream branch :
git checkout origin/branch_name
Finally, if you want to continue developing on that branch, you should
git checkout -b branch_name
git rev-parse tagname
git reset --hard tagname
git reset --soft tagname
git log --format=fuller
There are two kinds of timestamp in git: a GIT_AUTHOR_DATE
and a GIT_COMMITTER_DATE
. Although in most cases they both store the same value, they serve slightly different purposes. As the documentation depicts :
The author is the person who originally wrote the work, whereas the committer is the person who last applied the work.
So if, for instance, you send in a patch to a project, the author date will be when you made the original commit but the committer date will be when the patch was applied. Another common scenario is rebasing: rebasing will alter the commit date, but not the author date.
$ export GIT_AUTHOR_DATE="Wed Feb 16 14:00 2037 +0100"
$ export GIT_COMMITTER_DATE="Wed Feb 16 14:00 2037 +0100"
$ git commit ...
git log --since='yesterday'
git log --since="1 week ago" --until="yesterday"
git whatchanged
also, the since
and until
options can be used to filter history
git whatchanged --since='2 weeks ago' --until=`2 days ago`
to remove local branch
git branch -D branch_name
to remove a remote branch
git push --delete remote_name branch_name
git show commit_hash -- file_name
First, tag the tip of the branch by archiving it, and then delete the branch.
git tag archive/<branchname> <branchname>
git branch -d <branchname>
git checkout master
The branch is now deleted and can be retrieved later by checking out the tag and recreating it.
git checkout archive/<branchname>
git checkout -b new_branch_name
or alternatively :
git checkout -b new_branch_name archive/<branchname>
First rename your local branch. If you are on the branch you want to rename:
git branch -m new-name
If you are on a different branch:
git branch -m old-name new-name
Then, delete the old-name remote branch and push the new-name local branch.
git push origin :old-name new-name
Finally, reset the upstream branch for the new-name local branch. Switch to the branch and then:
git push origin -u new-name
Rebase leaves the old state as ORIG_HEAD
, so we can revert the last rebase by running:
git reset --hard ORIG_HEAD
suppose you have made a single legitimate commit on a wrong branch and now you want to move the changes to the correct one.
First, on the wrong branch, reset the changes you've committed :
git reset --soft HEAD~1
Now the changes are back in the staging area. Stash them :
git stash
Then, checkout into the correct branch
git checkout correct_branch_name
And just pop the stashed files
git stash pop
Now if you do a git status
, you'll see the changes are in the staging area of the correct branch and ready to be committed.
git branch -a --contains tag_name
git update remote origin --prune
git stash pop = git stash apply && git stash drop.
git stash pop
throws away the (topmost, by default) stash after applying it, whereas git stash apply
leaves it in the stash list for possible later reuse (or you can then git stash drop it).
This happens unless there are conflicts after git stash pop, in this case, it will not remove the stash, behaving exactly like git stash apply.
git log --decorate
git checkout -b [branch_name] origin/[branch_name]
Assuming you are on your working branch and you are the only one working on it.
git fetch && git rebase origin/master
To summarize the log output to commits that are made on a specific branch, first checkout the desired branch
git checkout [branch_name]
Then,
git log --graph --decorate --pretty=oneline --abbrev-commit --first-parent
git checkout -- .
git checkout -- [filename]