This is a note that I collected from work

Clone from GIT and develop

git clone https://github.com/wahengchang/testgit git fetch origin git add . git commit -m “edited by 2” git push origin

Pull from remote

git pull origin branch1 //To see change on remote //Check if it is out of data git remote show origin

The last push information

git show-branch *feature1 add and switch to New Branch git branch feature1 git checkout feature1

Branch Merge to Master

git checkout master git merge feature1 git push origin master

Switch branch

git branch git branch -v git branch feature1 git checkout feature1

List committed files

git show — name-only

To see change on local unPush commit

git log origin/feature1..HEAD git diff origin/feature1..HEAD git diff — name-only

Cancel unPush commit ( multi cancel, keep changes)

git reset //or git reset filename //or git log origin/feature1..HEAD

Confirm to remove (local delete, remotely existed)

git rm fileName //Revert push git revert origin

Undo push , Unpush

git reset — hard HEAD@{1} git push -f origin

Deploy from local branch->remote branch

git push origin dev:master

Go back to certain commit from different branch

git cherry-pick cb7dfbcfa988a11f0ba1ea9b37a9ec32ce02a674

Go back to certain commit

git reset cb7dfbcfa988a11f0ba1ea9b37a9ec32ce02a674

Stash all file, and pop

git stash git stash pop

You have not concluded your merge (MERGE_HEAD exists).

git merge — abort git reset — merge git add . git commit -m “” git push origin //conflict git add . git commit -m “merge” git push origin

Sync local branch

remove no-use branch

git remote prune origin

Rewrite History

git rebase -i HEAD~4

# change “pick” to “r”

#change the old logs to new logs

Pull(checkout) PR to local

git checkout -b xxx prBranchName

git pull git@gsomething:someone/repo-name

After Fix conflict

git checkout originBranchName

git merge --no-ff prBranchName

git push origin originBranchName

Squash N commits to ONE

From: https://stackoverflow.com/questions/2563632/how-can-i-merge-two-commits-into-one

Say your history is

$ git log --pretty=oneline



a931ac7c808e2471b22b5bd20f0cad046b1c5d0d c

b76d157d507e819d7511132bdb5a80dd421d854f b

df239176e1a2ffac927d8b496ea00d5488481db5 a

Running git rebase --interactive HEAD~2 gives you an editor with

git rebase --interactive HEAD~2 pick b76d157 b

squash a931ac7 c //change pick to squash



# Rebase df23917..a931ac7 onto df23917

#

# Commands:

# p, pick = use commit

# r, reword = use commit, but edit the commit message

# e, edit = use commit, but stop for amending

# s, squash = use commit, but meld into previous commit

# f, fixup = like "squash", but discard this commit's log message

#

# If you remove a line here THAT COMMIT WILL BE LOST.

# However, if you remove everything, the rebase will be aborted.

#

and save-quitting your editor, you’ll get another editor whose contents are

# This is a combination of 2 commits.

# The first commit's message is:



b



# This is the 2nd commit message:



c

done

$ git log --pretty=oneline

18fd73d3ce748f2a58d1b566c03dd9dafe0b6b4f b and c

df239176e1a2ffac927d8b496ea00d5488481db5 a

Syncing a fork

$ git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git

$ git fetch upstream

$ git pull upstream master

Rebase from branch