Friday, June 27, 2014
Git Frequently Used Commands (Local Repository)
Setup Your Identity (Configuration)
git config --global user.name "your_full_name_here"
git config --global user.email "your_email@here"
Initialize a repository
git init
Add a file to track
git add file_name
Add commit
git commit -a
Amend last commit comment
git commit --amend
Undo a commit / conflict merge (retain modification: --soft, ignore modification: --hard)
git reset HEAD^ --soft
Create feature branch
git branch feature_branch
git checkout feature_branch
Ignore an old commit
git rebase -i hash_id_of_before_the_old_commit
(delete the id of the old commit in editor)
Add a fixup for the old commit
git commit --fixup id_of_the_commit
git rebase -i --autosquash id_BEFORE_the_old_commit
(command before fixup commit should be “fixup”)
Apply master’s changes to feature branch
git checkout feature_branch
git rebase master
Merge feature branch back to master
git checkout master
git merge feature_branch
Restore a single file from last commit
git checkout filename
Restore ALL files from last commit
git reset --hard
Stash and Restore ALL files from commit
git stash
Restore from stash
git stash apply
Clear stash
git stash clear
Subscribe to:
Posts (Atom)