Skip to content

marcpeters2/git_cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 

Repository files navigation

git_cheatsheet

A list of commonly used git commands

Branches

Listing

List local branches:

git branch

List remote branches:

git branch -r

List all local and remote branches:

git branch -a

Getting stuff

Retrieve a specific file (or files) from another branch:

git checkout <branch_name> -- <file_paths>

Deleting

Delete local branch:

git branch -d <branch_name>

Delete remote branch:

git push origin --delete <branch_name>

Diffs

Show diff between the current branch and another branch:

git diff other_branch..

Show diff between a local file and a remote file that may be on different paths (files are in different folders):

git diff remotename/branchname:path/to/file.txt other/path/to/file.txt

OR

git diff HEAD:other/path/to/file.txt remotename/branchname:path/to/file.txt

Show a summary of files changed between two branches

git diff --name-status branch1..branch2

... or to compare against the current branch:

git diff --name-status ..otherBranch

Remotes

Add a remote:

git remote add remoteName git://github.com/user/repo.git
git fetch remoteName

Commits

Change the commit message (amend) the most recent commit on the current branch:

git commit --amend

Merges

Perform a merge using a different merge strategy (ie. "patience"):

git merge -s recursive -Xpatience <branch_name>

Choose which file version to keep during a merge:

git checkout --theirs /path/to/file

OR

git checkout --ours /path/to/file

Pushing changes

Simultaneously push and create an upstream branch to track your current branch:

git push -u origin branchname

This has the same effect as:

git push --set-upstream origin branchname

Undoing things

Revert changes to a file by pulling that file from another branch:

git checkout branchname -- path/to/file.js

About

A list of commonly used git commands

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published