Saturday, June 11, 2016

Most frequently used git commands


init local repo and push it to the remote repo (it has to be already created on github)
git init
git add .
git reset [file to exclude]
git commit -am "First commit"
git remote add origin [github address]
git push origin master
add remote repo, give it a name [name] and fetch it locally
git remote add [name] [github address]
git fetch [name]
create a new branch based on some branch
git checkout -b [new_branch] [some_branch]
create a new branch on top of uncommited changes
git checkout -b [new_branch]
edit/merge history of N last commits (replace pick with squash to merge commit)
git rebase -i HEAD~N
get file from the other branch
git checkout [branch] -- [file]
rebase on top of some branch
git rebase [branch]
  if merge conflict - resolve by hand then
  git add [resolved file]
  git rebase --continue
  if merge conflict - use either ours or theirs file
  git checkout --ours|--theirs [file]
  git add [resolved file]
  git rebase --continue
cherry-pick a commit
git cherry-pick [commit 6-number hash]
patch
   add '.patch' to the pull request URL and press 'Enter' in the browser
   curl -L [url] > /tmp/my.patch
   git apply (--check) /tmp/my.patch
git cherry-pick [commit 6-number hash]
delete a branch
git -d [branch]
revert local changes to the last commit
git reset --hard HEAD
git push from some local branch to some remote
git push <REMOTENAME> <LOCALBRANCHNAME>:<REMOTEBRANCHNAME>
Pull/fetch/merge/rebase reference
https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/

No comments:

Post a Comment