Clone and Change repo

  • http://stackoverflow.com/questions/22906917/how-to-move-git-repository-with-all-branches-from-bitbucket-to-github
  • http://stackoverflow.com/questions/2432764/change-the-uri-url-for-a-remote-git-repository

Origin

git remote set-url origin https://github.com/user/repo2.git
git remote show original
git push

Tag

// see local tags
git tag

// tag current branch
git tag -a 2.1.2-release -m 'Updated: xxx.'

// push tag to remote
git push --tag


// Delete tag localy
git tag --delete 2.1.2-release


// Delete tag remotely
git push --delete origin 2.1.2-release

Branching and Merging

// See branchs
git branch


// Create a branch and checkout it.
git checkout -b hotfix

// This is shorthand for :
// git branch hotfix
// git checkout hotfix


// Delete branch
git branch -d hotfix
// Delete remote branch
git push origin --delete hotfix


// Push branch to remote server
git push --set-upstream origin hotfix


// Merge
git merge hotfix

// You can merge branch by follows if error [fatal: refusing to merge unrelated histories] occurred.
git merge develop --allow-unrelated-histories
// http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories

// See stutas if conflicts occurred
git status


// Merge files
// https://git-for-windows.github.io/
// http://stackoverflow.com/questions/426026/git-on-windows-how-do-you-set-up-a-mergetool
git mergetool
git commit -m 'merge finished'

// edit file directly
git add .
git commit -m 'merge finished'

// Cancel last commit
// http://stackoverflow.com/questions/927358/how-to-undo-last-commits-in-git
git reset HEAD~

// Undo cancel last commit
// http://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1
git reflog
git reset --hard <id>

// Discrad all changes
// http://stackoverflow.com/questions/1090309/git-undo-all-working-dir-changes-including-new-files
git reset --hard

// Discrad all change (include untracked files)
// http://stackoverflow.com/questions/14075581/git-undo-all-uncommitted-changes
git clean -fdx

// Change last commit message
// http://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commits
git commit --amend -m "New commit message"

Other Tips


// See last 2 commit & its detail
git log -p -2


// Discrad file change
git checkout -- README.md


// See changes you just made.
git diff

// Disabled lf -> crlf
// http://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf
git config core.autocrlf false

Repos & Sites