git cheat sheet

February 21, 2019

Git is a free open source distributed version control tool that tracks changes in your file. As a developer believe me you need it more than anything else (’Just kidding πŸ˜›β€™). But its important.

Advantages

  • Enhance collaboration
  • Storage of versions
  • Enables analysis of project evolution

Github is a social network that allow developer to store and share code

Git Terminal commands

Here is a cheat sheet of commands you might find useful and come to love:

    git config --global user.name "example_user"

-sets a name identifiable for credit when reviewing version history

    git config --global user.email "exampleuser@email.com"

-set an email address associated with the version history

    git config --global color.ui auto

-set automatic coloring of git in the command line

    git init

-name or rename your branch

$git branch -m main. 

-initialize a local directory on you computer as a git repository

    git clone

-retrieve a repository from a central remote hosting

    git status

-show modifications on the working tree

    git add <fileName>

-add the named file to the staging area

    git add .

-adds all tracked files to the staging area

    git reset

-un stage a file but retains changes in the working directory

    git diff

-shows changes between commits,commit and working tree

    git diff --staged

-show changes made to a file in the staging area

    git commit -m "commit message"

-commits your staged content as a new commit snapshot

    git branch <branchName>

-creates a new branch

  • Branches enables you to isolate your changes and context and integrate them together when you’re ready*
    git branch -a

-lists all your branches

    git checkout <branchName>

-switches to the named branch

    git merge <branchName>

-merge the specified branch with the current one

    git log

-shows all commits in the current branch

    git log branchB..branchA

-shows commits on branchA that are not on branchB

    git log --follow <fileName>

-shows commits that changed a file,even if it was renamed

    git diff branchB...branchA

-shows changes that are in branchA and not in branchB

    git show <SHA>

-shows any object in git in human-readable format

    git rm <fileName>

-removes the file from the project and stage the change

    git mv <currentPath> <newPath>

-changes an existing path and stage the move

    git log --stat -M

-shows all commits log and paths changed

    git remote add <alias> <url>

    git remote add origin https://github.com/...

-add a remote git url to your local repository

    git fetch <alias>

-fetch all the branches from a central remote repository

    git merge <alias>/<branch>

-merge a remote branch into your current one locally

    git push <alias> branch

    git push -u origin main

-transmit local branch to the remote repository branch

    git push -u <alias> branch    OR
    
    git push --set-upstream <alias> <branchName>

-push the current branch and set the remote as upstream

    git pull

-fetch and merge any commits from the remote tracking branch

    git rebase <branch>

-apply any commits on current branch ahead of specified one

    git reset --hard <commit>

-clear staging area,rewrite working tree from specified commit

    git stash

-save modified and staged changes

    git stash list

-list stack order of stashed file changes

    git stash pop

-write working from top of stash stack

    git stash drop

-discard changes from top of stash stack

    git restore --staged <fileName>

-revert non committed changes from the staging area

echo "# new" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:bwakedavis/new.git
git push -u origin main

OR

git remote add origin git@github.com:bwakedavis/new.git
git branch -M main
git push -u origin main

Profile picture

Written by Davis Bwake A fullstack developer who likes JavaScript and everything web 3.0(BlockChain..) follow me on twitter

My tech stack is HTML, CSS,JavaScript, ReactJS, NodeJS, Solidity

Am currently open to remote job oppurtunities.

Checkout my projects

YouTube