Home

Awesome

man-git

a collection of git tips and tricks

Tips and Tricks (by command)

git branch

Delete a local branch

git branch -d <branch-name>

source

Delete an unmerged local branch

git branch -D <branch-name>

source: git man pages

git checkout

Checkout specific file from another branch

git checkout <branch_name> -- <paths>

source

git diff

Show the files and changes that have been staged

git diff --cached

source

Show the difference between two (local) branches

# diff to show what is in branch-2 that is not in branch-1 (..)
git diff branch-1..branch-2

# diff to show what is in branch-1 that is not in branch-2 (..)
git diff branch-2..branch-1

# diff based on the common ancestor of branch-1 and branch-2 (...)
git diff branch-1...branch-2

source

# list only the names of the files
git diff branch-1..branch-2 --name-only

source

# list the status and name of each file
git diff branch-1..branch-2 --name-status

source

git push

Delete a remote branch

git push origin --delete <branch-name>

source

git remote

Change/Update the remote repository URL

git remote set-url <remote-name> <remote-url>

# for example, change origin url to github.com/user/repo-name
git remote set-url origin https://github.com/user/repo-name.git

source

git reset

Squash some commits

# move the head back two commits as the contents of those
# two commits gets squashed onto the index
git reset --soft HEAD~2
# commit the now squashed changes
git commit

source

git tag

Delete a remote git tag

git tag -d v1.0.0
git push origin :refs/tags/v1.0.0

source

Links (by command)

git fetch

git ls-files

List all files staged for deletion (and then do something with them)

# simply list the files staged for deletion
git ls-files --deleted -z

# perform a `git rm` on the files, putting them on the index
git ls-files --deleted -z | xargs -0 git rm

# perform a `git checkout --` on the files, unstaging them
git ls-files --deleted -z | xargs -0 git checkout --

source

git pull

git reset

Resources

Commit Messages

Tools

Workflows

License

© 2015 Josh Branchaud

This repository is licensed under the MIT license (see LICENSE for details).