git usage

part-1

General

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# add new file
git add [YOUR_FILE] [YOUR_FILE] [YOUR_FILE]
# add new files
git add .
# commit
git commit -m "[YOUR_COMMIT_MESSAGE]"
# reset a commit
git reset HEAD
# push your commit(s) to repo
git push
# pull files from repo
git pull


# stash
git stash
git stash list
git stash pop
git stash drop

# discard the changes to one file in the repo
git checkout -- path/to/the/file.txt

# show file changes
git diff path/to/the/file.txt

git amend

1
2
3
# update last commit message
git add add-to-last-commit.file
git commit --amend

Branch

1
2
3
4
5
6
7
8
9
10
11
12
13
# list branch
git branch
# switch branch
git checkout [BRANCH_NAME]
# create branch
git checkout -b [NEW_BRANCH_NAME]

# rename
git branch -m rename-from rename-to

# remove
git branch -d the_local_branch
git push origin --delete the_remove_branch

Export / Archive

1
2
git checkout-index --prefix=git-export-dir/ -a
git archive --format zip --output zipfile.zip master

git log

1
2
3
git log
git reflog
git reset HEAD@{index}

Merge

1
2
git checkout Dev
git merge --no-ff -m 'Merged in feature/Malls-Controller (pull request #1)' remotes/origin/feature/Malls-Controller

git flow

1
2
3
4
5
6
7
# install
brew install git-flow

git flow init
git flow feature start some_awesome_feature
git flow feature finish some_awesome_feature
git flow feature publish some_awesome_feature

git branch up to date

1
2
3
4
5
git checkout newBranch
git fetch
git merge origin/master
# reference
https://stackoverflow.com/questions/19758915/keeping-a-branch-up-to-date-with-master