Skip to content

theriyazo/Git-Cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

GitHub CheatSheet by RiyazAhamad(theriyazo)

Created: November 6, 2021 1:17 AM

Materials: src_1, src_2

  • Reviewed

Git Commit History # :

💲 git log
  • Going back to a commit #

    💲 git checkout < hash-code >

Most Used Git Commands

Rename master to main #

💲 git branch -m master main

Initial Git Login commands

  • Configure your user name

    💲 git config --global user.name "your_github_username"
  • Configure your email id used for github

    💲 git config --global user.email "[email protected]"

List hidden files

💲 ls -a

Complete Log

💲 git log
  • gives the <hashNumber> and details
  • to exit git log → q or z

Logs changes

💲 git add < file >

Adding commit message

💲 git commit -m "< message >"

Logs commit

💲 git commit -m < file >

current tree status

💲 git status

vi editor

  • enter vi

    💲 vi
  • exit vi editor

    💲 [ESC] : x

Files

  • To create file

    💲 touch < file >
  • To look inside file

    💲 cat < file >
  • Remove/Delete file

    💲 rm -rf < file >

Staging

  • Adding a particular file

    💲 git add < file >
  • Adding all the files

    💲 git add .
  • To add all files with the particular extension

    💲 git add *.< fileExtension >
  • Un-stage particular commit changes

    💲 git reset < hashNum >
  • Removing file from stage

    💲 git restore - - staged < file > 💲 git rm - - cached < file >

Stash

  • Adding files to Stash

    💲 git stash
    • adds all the files to stash
  • Adding message to a stash

    💲 git stash save "< message >"
  • Pop the Stash files

    💲 git stash pop
  • To clear the stash

    💲 git stash clear
  • To list stash

    💲 git stash list
  • To Pop particular files

    💲 git stash pop stash@{indexNo}

Remote Repository

  • Adding remote Repo to local repo

    💲 git remote add origin < https://gitRepoURL.git >
  • To check attached URLs

    💲 git remote -v
  • To push changes to remote Repo

    💲 git push origin < HEAD Branch >
    • for main or master branch it will be git push origin main or git push origin master
    • for branch → git push origin <branchName>
  • To pull remote repo commits/changes

    💲 git pull
  • To remove remote repo URL

    💲 git remove remote origin
  • To update remote repo

    💲 git remote set-url origin < newRemoteRepoURL.git >
  • To add add Upstream (forked repo URL)

    💲 git remote add upstream < URL >
  • To check remote repo

    💲 git remote
  • To clone remote repo

    💲 git clone < repoURL >

Branching

  • To Create new branch

    💲 git branch < branchName >
  • To Switch to particular branch

    💲 git checkout < branchName >
  • To Create new branch and switch to it

    💲 git checkout -b < branchName >
  • Merge the current branch

    💲 git merge < branchName >
    • make sure you've switched to the branch you want the other branch to merge with.

Basic git bash commands

  • To move previous directory

    💲 cd ..
  • To move to home directory

    💲 cd ~
  • To move to root

    💲 cd /