Skip to content

Instantly share code, notes, and snippets.

@brygrill
Last active August 1, 2018 12:51
Show Gist options
  • Save brygrill/b99fd518cf07c3424c94e9ed37a471ff to your computer and use it in GitHub Desktop.
Save brygrill/b99fd518cf07c3424c94e9ed37a471ff to your computer and use it in GitHub Desktop.
# checkout remote branch
$ git fetch
$ git checkout <remote-branch-name>

# list local branches
$ git branch

# list all branches
$ git branch -a

# status
$ git status

# remove file from tracking but dont delete it
$ git rm --cached <file name>

# view files in last commit
$ git show --name-only <commit id>

# remove file from commit that is not pushed
$ git reset --soft HEAD^
$ git reset HEAD path/to/unwanted_file
$ git commit -c ORIG_HEAD

# add all files to commit
$ git add --all

# commit files
$ git commit -m "message"

# push remote feature branch
$ git push origin feature/<branch-name>

# get latest from remote
$ git fetch

# switch to dev
$ git checkout dev

# pull changes from remote
$ git pull

# delete local feature branch (must have different branch checked out)
$ git branch -d feature/<branch-name>

# prune origin
$ git remote prune origin

# new branch from current branch and switch to it
$ git checkout -b feature/<another-branch-name>

# merge dev changes into feature branch
# with feature branch checked out...
$ git fetch origin
$ git merge origin/dev
$ :wq # save commit in vim

# save credentials
# https://git-scm.com/docs/git-credential-store#_examples
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

[several days later]
$ git push http://example.com/repo.git
[your credentials are used automatically]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment