You are on page 1of 2
GitHub GIT CHEAT SHEET Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference. INSTALLATION & GUIS \With platform specific installers fr Git, GitHub also provides the ease of staying up-to-date with the latest releases of the command line toot wale providing agraphical user interface for day-to-day. Interaction review, and repository synchronization GitHub for Windows hetps://windaws github,com GitHub for Mac https://mac githubcom For Linux and Solaris platforms, thelatest release is available on the oficial Git web sit. Git for AllPlatforms hetpy//git-semcam ‘SETUP Configuringuser information used across alllocal repositories git config --global username “[tirstname Lastname]” set a name that is identifiable for credit when review version history git config --global user-enail “[valid-enail]" set an email address that willbe associated with eachhistory marker git config --global color.ui auto set automatic command line colaring for it for easy reviewing, SETUP & INIT Configuring user information initializing and cloning repositories git inte initialize an existing directory asa Git repository git clone [ut] retrieve an entirerepasitory from ahostedlocation via URL STAGE & SNAPSHOT Working with snapshots and the Git staging area git status ‘show modified files in working director, staged for your next commit git ada [eite] ‘adda file ast looks now to your next commit (stage) git reset [¢ile] Unstage ale while retaining the changes in working directory git cite diff of whats changedbut not staged git dite --staged iff of what is staged but nat yet committed git comit -m “[descriptive message] commit your staged content as anew cammit snapshot BRANCH & MERGE Isolating work inbranches, changing context, and integrating changes ‘git branch listyourbranches.a*willappear next to the currently active ranch ‘git branch [branch-nane] create anewbranch at the current commit ‘git checkout ‘switch to another branch and check it out into your working directory ‘git merge [branch] merge the specified branchshistory into the current ane ‘tt Log showall commits nthe currantbranch’s history oO INSPECT & COMPARE Examining logs, diffs and object information ait log show the commit history or the currently active branch ft Log brancha. .branena show the commits on brancha that are not on branchB git log --foltow [este] show the commits that changed file, even across renames git Aise branch®....brancha show the dif of what isin branchA that snot inbranch® git show [SHA] show any objectin Git inbuman-readable format TRACKING PATH CHANGES: ‘Versioning fileremoves and path changes git am [file] delete the file from project and stage the removal for commit git av [existing-path] [new-path] change an existing le path and stage the move git tog --stat -M show all commit logs with indication of any paths that moved IGNORING PATTERNS Preventing unintentional staging or commiting of files Logs/, scnotes patternt/ Save file with desired patterns as gitigrore with elther direct string, matches or wildcard giobs. git config --global core.excludestite [£ite] system wide ignore pattern for alllocal repositories GitHub Education Teach nd learn better, together. GitHub free for students and teach- ers, Discounts available for other educational uses. ‘SHARE & UPDATE Retrieving updates from anather repository and updatinglocal repos git remote add [alias] Curt] ‘add agit URL as analias git teten [alias] fetch downall the branches from that Git remote git merge [alias]/[oranch] ‘merge aremote branch into your current branch tobring t upto date git push [alias] [branch] “Tansmit local branch commits to the remote repository branch git pull fetch and merge any commits from the tracking remote branch REWRITE HISTORY Revaiting branches, updating commits and clearing history git xebase [branch] apply any commits of current branch ahead of specified ane git reset --hard [commit] clear staging area, rewrite working tree from specified commit ‘TEMPORARY COMMITS Temporarily store madified, tracked files inorder to change branches, git stash Save modified and staged changes Git stash List Uststack-order of stashed le changes att stash pop write working rom top af stash stack ait stash dzop discard the changes from top of stash stack 22 education@github.com ‘© education github.com

You might also like