Skip to content

Instantly share code, notes, and snippets.

@yanxun827
Created January 9, 2018 12:56
Show Gist options
  • Save yanxun827/f7a20ec5314da6b963e5d7c54620f66b to your computer and use it in GitHub Desktop.
Save yanxun827/f7a20ec5314da6b963e5d7c54620f66b to your computer and use it in GitHub Desktop.

Revisions

  1. yanxun827 created this gist Jan 9, 2018.
    41 changes: 41 additions & 0 deletions git commands
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    git config —-global
    git config —-list

    git init [repository name] (create a local repo)

    git clone [repository name] copies a remote repo to store it locally
    git remote add origin [remote repo link] (links up the local and remote repos)
    git push -u origin master

    git add [filename]
    git add *.html adds all untracked html files
    git add . adds every untracked files(including files in subdirectories)

    git diff (works for file that has been modified when not staged(added))
    git diff —-staged (works for file that has been staged)

    git branch [branch name] (create new branch from current branch)
    git checkout [branch name] (go to branch)
    git checkout -b [branch name] (create new branch and go to branch)
    git branch (lists all the branches and which branch currently in)
    git branch -d [branch name]
    git merge (has to be done on the receiving branch, and if no commits on receiving branch, it will be a fast forward merge, if not, need to insert message.)

    git commit -m "message for this whole commit (including all files)"

    If commit without message, an editor (vim) would be opened to allow message to be entered. Type :wq to save the message and exit vim.

    git push (push to remote repo)
    git pull

    To sync original repo fork with own fork
    ```bash
    git fetch upstream
    git merge upstream/master
    ```

    However, pull would introduce merge commits. To avoid that to have a linear history, [use these commands](https://www.derekgourlay.com/blog/git-when-to-merge-vs-when-to-rebase/):
    ```bash
    git fetch origin
    git rebase −p origin/develop
    ```