Link Search Menu Expand Document

Basic Git

Git is to synchronise files between local machine and remote repository. I was quite confused in the beginning but eventually got the logic after trying again and again.

  • Origin » Remote address (such as GitHub or Bitbucket)
  • Local » Local PC (Local)


Table of contents

Git basic command

    git init
    git add [file-name]
    git status
    git commit
    git checkout -b [new-branch-name]
        #switch to new branch
    git checkout [existing_branch]
        #switch branch
    git push [remote] [branch-name]
    git pull
    git clone
    git branch
        #to checkout which branch am I on
    git branch -D [local-branch-name]
        #delete the branch locally 
    git push origin -d [remote-branch-address]
        #delete remote branch
    git fetch origin 
        # to get updated from origin 

Drop untracked change

Changes not staged for commit:

    git status
        # Changes not staged for commit: ...
    git stash save --keep-index
        # Saved working directory and index state WIP on master: ...
    git stash drop
        # Dropped refs/stash@{0}
    git status
        # nothing to commit, working tree clean

Detached HEAD

Seeing this [detached HEAD c253b43], run this:

    git push HEAD:master

Search & replace

        #example run: $ :%s/search-word/changed-word/g
        #this is to search for the entire file 

    :8,10 s/search/replace/g
        #this is to search within range of 8-10

Github setup

Full Github tutorial

  1. Check remote:

     git remote -v 
         #origin ssh:// (fetch)
         #origin ssh:// (push)
  2. Switch SSH to HTTPS:

     git remote set-url origin
  3. If directory is not set remote

     git remote add origin ssh://
     git remote -v 
         #see the path is set 
  4. Simple git init » git add [file]

     echo "hello world" > test1.txt
     git add test1.txt 
     git status