git and github - tlam/Wiki GitHub Wiki

git

More commands

  1. Remove file from index

     git rm --cached indexed_file
    
  2. Cloning from remote ssh with a specific port 1234

     git clone ssh://[email protected]:1234/home/username/project
    
  3. Checking out from master

     git fetch; git checkout -f origin/master
    
  4. Restore an uncommitted deleted file, deleted_file.py:

     git reset -- deleted_file.py
     git checkout -- deleted_file.py
    
  5. Stash local change while updating tree:

     git stash --patch
    

    Press a to stash the change you want and d to skip over the change you don't want stashed. git pull and git stash pop can be followed to get the latest tree and merge the old change back.

  6. Disable paged output for git branch

     git config --global pager.branch false
    

Branching

  1. Create a new branch called maple

     git branch maple
    
  2. See all branches

     git branch
       maple
     * master
    
  3. Switch to the maple branch

     git checkout maple
    
  4. After committing a change to the branch, push the branch to github

     git push origin maple
    
  5. Delete local branch

     git branch -d maple
    
  6. Delete a branch remotely

     git push origin --delete maple
    
  7. Git revert

Git Revert

  • Create a git branch, git branch revert-new-attribute
  • git checkout revert-new-attribute
  • git revert -m 1 abc123
  • git push --set-upstream origin revert-new-attribute