Migrate Master to Main
git branch -m master main
gpom ( git push origin main )
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
git push origin --delete master
git push code --delete master
Sparse checkout
https://github.blog/2020-01-17-bring-your-monorepo-down-to-size-with-sparse-checkout/
git init
git remote add origin <url>
git config core.sparseCheckout true
echo "app" >> .git/info/sparse-checkout
git pull origin master
git checkout tags/v1.0
removing commit history of file
https://help.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \ --prune-empty --tag-name-filter cat -- --all
git push origin --force --all
$ git config --list
$ git config --local --list
$ git config --global --list
$ git config --system --list
$ git config --global user.name “[firstname lastname]”
$ git config --global user.email “[valid-email]”
$ git config --global color.ui auto
$ git config --global core.editor vi
<repo>/.git/config
~/.gitconfig
/etc/gitconfig
There are two ways:
Via SSH
$ git clone ssh://user@domain.com/repo.git
Via HTTP
$ git clone http://domain.com/user/repo.git
$ git init
$ git status
$ git diff
$ git add .
$ git add -p <file>
$ git commit -a
$ git commit
$ git commit -m 'message here'
$ git commit -am 'message here'
$ git commit --date="`date --date='n day ago'`" -am "<Commit Message Here>"
Don't amend published commits!
$ git commit -a --amend
Don't amend published commits!
$ git commit --amend --no-edit
GIT_COMMITTER_DATE="date" git commit --amend
$ git commit --amend --date="date"
$ git stash
$ git checkout branch2
$ git stash pop
$ git stash apply
- *{stash_number}* can be obtained from `git stash list`
$ git stash apply stash@{stash_number}
$ git stash drop
$ git grep "Hello"
$ git grep "Hello" v2.5
$ git log
$ git log --oneline
$ git log --author="username"
$ git log -p <file>
$ git log --oneline <origin/master>..<remote/master> --left-right
$ git blame <file>
$ git reflog show
$ git reflog delete
$ git branch
$ git branch -a
$ git branch -r
$ git checkout <branch>
$ git checkout <branch> -- <filename>
$ git checkout -b <branch>
$ git checkout <commit-hash> -b <new_branch_name>
$ git branch <new-branch>
$ git branch --track <new-branch> <remote-branch>
$ git branch -d <branch>
$ git branch -m <new_branch_name>
You will lose unmerged changes!
$ git branch -D <branch>
$ git tag <tag-name>
$ git tag -a <tag-name>
$ git remote -v
$ git remote show <remote>
$ git remote add <remote> <url>
$ git fetch <remote>
$ git remote pull <remote> <url>
$ git pull origin master
$ git pull --rebase <remote> <branch>
$ git push remote <remote> <branch>
$ git push <remote> :<branch> (since Git v1.5.0)
OR
$ git push <remote> --delete <branch> (since Git v1.7.0)
$ git push --tags
$ git config --global merge.tool meld
$ git mergetool
$ git merge <branch>
Don't rebase published commit!
$ git rebase <branch>
$ git rebase --abort
$ git rebase --continue
$ git add <resolved-file>
$ git rm <resolved-file>
$ git rebase -i <commit-just-before-first>
Now replace this,
pick <commit_id>
pick <commit_id2>
pick <commit_id3>
to this,
pick <commit_id>
squash <commit_id2>
squash <commit_id3>
$ git reset --hard HEAD
$ git reset HEAD
$ git checkout HEAD <file>
$ git revert <commit>
$ git reset --hard <commit>
$ git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature
$ git reset <commit>
$ git reset --keep <commit>
$ git rm -r --cached .
$ git add .
$ git commit -m "remove xyz file"
Improved Git-flow
$ brew install git-flow-avh
$ port install git-flow
$ sudo apt-get install git-flow
$ wget -q -O - --no-check-certificate https://raw.githubusercontent.com/petervanderdoes/gitflow/develop/contrib/gitflow-installer.sh install <state> | bash
git flow init
OR
git flow init -d
git flow feature start MYFEATURE
git flow feature finish MYFEATURE
git flow feature publish MYFEATURE
git flow feature pull origin MYFEATURE
git flow feature track MYFEATURE
git flow release start RELEASE [BASE]
git flow release publish RELEASE
git flow release finish RELEASE
$ git flow hotfix start VERSION [BASENAME]
git flow hotfix finish VERSION