Skip to main content

Git

How to Git#

Usefull Git Commands

setup for user

git config --global user.name 'YOUR FULL NAME'git config --global user.email 'YOUR EMAIL ADDRESS'git config --global color.ui auto

setup&init

git init                                #initialize an existing directory as a Git repositorygit clone [url]                         #retrieve an entire repository from a hosted location via URLgit clone [url] [name of the folder]    #retrieve an entire repository from a hosted location via URL to the folder you want

work with branches

git branch                  #list your branches. a * will appear next to the currently active branchgit branch [branch-name]    #create a new branch at the current commitgit checkout                #switch to another branch and check it out into your working directorygit merge [branch]          #merge the specified branch’s history into the current onegit log                     #show the commit history for the currently active branchgit log branchB..branchA    #show the commits on branchA that are not on branchBgit diff branchB...branchA  #show the diff of what is in branch A that is not in branch B

remove and change

git rm [file]                       #delete the file from project and stage the removal for commitgit mv [existing-path] [new-path]   #change an existing file path and stage the move

stage and snapshot

git status                      #show modified files in working directory, staged for your next commitgit add [file]                  #add a file as it looks now to your next commit (stagegit reset [file]                #unstage a file while retaining the changes in working directorygit diff                        #diff of what is changed but not stagedgit diff --staged               #diff of what is staged but not yet commitedgit commit -m '[message]'       #commit your staged content as a new commit snapshot

share and update

git fetch [alias]           #fetch down all the branches from that Git remotegit merge [alias]/[branch]  #merge a remote branch into your current branch to bring it up to dategit push [alias] [branch]   #Transmit local branch commits to the remote repository branchgit pull                    #fetch and merge any commits from the tracking remote branch