Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickarthur/c61a6070c3c44b90e00a45a92614451f to your computer and use it in GitHub Desktop.
Save nickarthur/c61a6070c3c44b90e00a45a92614451f to your computer and use it in GitHub Desktop.
Git Commands

Discard unstaged changes

For a single file: git checkout path/to/file/to/revert

For all unstaged files: git checkout -- .

List all untracked files

git ls-files --others --exclude-standard

Active git config

/Users/[id]/.gitconfig

Display current config

git config --list

Clone

git clone https://github.com/lifeofreilly/HTTPdLight.git

Automatically fetch and then merge a remote branch into your current branch

git pull

View remote servers

git remote -v

Status

git status

Add

git add bla.java

Commit

git commit -m "Test commit for new repository"

Push

git push origin master

Create a new branch named cleanup and switch to it

git checkout -b cleanup

View any local commits I've made, that haven't yet been pushed to the remote repository

git log origin/master..HEAD

Basic merge (delete temporary branch)

git checkout master git merge cleanup git branch -d cleanup git push origin master

Switch to 3.1 branch and sync

git checkout 3.1 git pull

Add all html files in the directory public_html

git add public_html/*.html

List all available branches

git branch

Basic Branch, Merge and Push

  • git checkout -b mybranchname
  • vi
  • git add
  • git commit -m ""
  • git checkout master
  • git merge mybranchname -m ""
  • git push
  • git branch -d mybranchname (optional delete)

Create new branch in repository

  • git checkout -b feature_branch_name
  • git push -u origin feature_branch_name

Git Basic diff for changed files

git diff HEAD file

Show local branchs

git branch

Show local and remote branches

git branch -a

Show remoate branches

git branch -r

Create new pull request

git checkout -b mybranchname
git vi
git add
git commit -m ""
git merge master
git push -u origin mybranchname
In Web UI initiate pull request

List un-pushed changes

git log origin/master..HEAD
git diff origin/master..HEAD

Amend a commit message

git commit --amend -m "New commit message"

Diff local branch against master

git diff master my_local_branch

List commits in current branch

git log --pretty=oneline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment