git tips

  1. set ssh-keys and git won’t ask password in future.

  2. clone repository with ssh keys
    git clone git@github.com:haijunsu/ServerTools.git
    
  3. create develop branch on git hub
    git checkout -b develop origin/master
    git push -u origin develop
    
  4. create a branch to fix an issue
    git checkout -b test_issue origin/develop
    
  5. rebase current branch
    git branch
    git rebase origin/develop
    
  6. check git status
    git status
    
  7. add/discard file to track
    git add  <file>...
    git checkout <file> # discard changes
    
  8. commit/discard changes
    git commit -m "change comment here"
    git reset HEAD~ # discard commit
    
  9. push change to branch
    git push -u origin test_issue
    
  10. review changes in a branch (test_issue)
    git checkout develop
    git fetch origin
    git checkout test_issue && git pull --ff-only
    
  11. merge change to develop
    git checkout -b test_issue_merge develop
    git pull origin test_issue
    git fetch orign
    git checkout develop
    git pull
    git merge --no-ff test_issue_merge
    git push -u origin develop
    git branch -d test_issue_merge
    
  12. merge change to master
    git fetch origin
    git checkout develop
    git pull
    git merge master
    git push -u origin develop
    git checkout master
    git merge --no-ff develop
    git push -u origin master
    git checkout develop
    git merge master
    git push -u origin develop
    
  13. Only add modified files and deleted files
    git add -u
    
  14. Only add untracked files
    echo -e "a\n*\nq\n"|git add -i
    
Written on November 8, 2016