0% found this document useful (0 votes)
80 views

ZT Git Cheat Sheet

This cheat sheet provides concise summaries of common Git commands for creating and working with repositories, branches, commits, and synchronization. It outlines how to initialize a local repository, clone an existing one, observe repository status and changes, work with branches including creating, switching, merging and deleting branches, commit changes to the version history, tag commits, and synchronize changes with remote repositories by fetching, pulling and pushing.

Uploaded by

Aruneshwaran R
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

ZT Git Cheat Sheet

This cheat sheet provides concise summaries of common Git commands for creating and working with repositories, branches, commits, and synchronization. It outlines how to initialize a local repository, clone an existing one, observe repository status and changes, work with branches including creating, switching, merging and deleting branches, commit changes to the version history, tag commits, and synchronize changes with remote repositories by fetching, pulling and pushing.

Uploaded by

Aruneshwaran R
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Git Cheat Sheet

Create a Repository Working with Branches Make a change Synchronize


From scratch -- Create a new local List all local branches Stages the file, ready for commit Get the latest changes from origin
repository $ git branch $ git add [file] (no merge)
$ git init [project name] $ git fetch
List all branches, local and remote Stage all changed files, ready for commit
Download from an existing repository $ git branch -av $ git add . Fetch the latest changes from origin
$ git clone my_url and merge
Switch to a branch, my_branch, Commit all staged files to versioned history $ git pull
and update working directory $ git commit -m “commit message”
Observe your Repository $ git checkout my_branch Fetch the latest changes from origin
List new or modified files not yet Commit all your tracked files to and rebase
committed Create a new branch called new_branch versioned history $ git pull --rebase
$ git status $ git branch new_branch $git commit -am “commit message”
Push local changes to the origin
Show the changes to files not yet staged Delete the branch called my_branch Unstages file, keeping the file changes $ git push
$ git diff $ git branch -d my_branch $ git reset [file]

Show the changes to staged files Merge branch_a into branch_b


Finally!
Revert everything to the last commit
$ git diff --cached $ git checkout branch_b When in doubt, use git help
$ git reset --hard
$ git merge branch_a $ git command --help
Show all staged and unstaged
file changes
Tag the current commit Or visit https://training.github.com/
$ git diff HEAD
$ git tag my_tag for official GitHub training.
Show the changes between two
commit ids
$ git diff commit1 commit2

List the change dates and authors


for a file
$ git blame [file]

Show the file changes for a commit


id and/or file
$ git show [commit]:[file]

Show full change history


$ git log

Show change history for file/directory


including diffs
$ git log -p [file/directory]

You might also like