syedrfurqanali / Git-Cheatsheet

A collection of most used git commands.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Login credentials

πŸ’² git config --global user.name "your_username" πŸ’² git config --global user.email "your_email@mail.com"

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 /

About

A collection of most used git commands.