Swapna Kumar Panda
Swapna Kumar Panda

@swapnakpanda

23 Tweets 1 reads Mar 23, 2023
Be it Python, Java, PHP, C#, or JavaScript. Git is an essential tool for everything.
Useful Git commands that you can use for all your GitHub repos:
➊ git init
βž€ Initializes an existing directory in the local file system as a Git repository.
❯ git init
βž‹ git clone
Retrieves an entire repository from a hosted location via a valid Git URL.
βž€ Cloning from remote repository
❯ git clone [URL]
➁ Cloning a specific branch
❯ git clone --branch <name> [url]
➌ git add
βž€ Add a file to the staging area
❯ git add [file]
➁ Add all files to the staging area
❯ git add -A
βž‚ Add all deleted and modified files only to staging area
❯ git add -u
βžƒ Add all files in the current working directory to the staging area
❯ git add .
➍ git rm
βž€ Deletes the file from the project and stages the removal for commit.
❯ git rm [file]
➎ git mv
βž€ Changes an existing file path and stages the move.
❯ git mv [existing-path] [new-path]
➏ git commit
βž€ Commits the staged contents as a new commit snapshot.
❯ git commit -m "message"
➁ Adds modified files to the staging and, commits
❯ git commit -a -m "message"
βž‚ Fixes previous commit message
❯ git commit --amend -m "message"
➐ git branch
List, Create or, Delete Branches
βž€ List branches
❯ git branch
➁ Create a new Branch at the current commit
❯ git branch [branch-name]
βž‚ Delete a Branch
❯ git branch -d [branch-name]
βž‘ git status
βž€ Shows the paths of modified files in the working directory.
❯ git status
βž’ git diff
Show changes between commits.
βž€ To see the diff of what is changed, but not staged
❯ git diff
➁ To see the diff of what is staged, but not committed
❯ git diff --staged
βž‚ To see the diff between the 2 branches
❯ git diff BranchA...BranchB
βž“ git log
βž€ Shows the commit history for the currently active branch.
❯ git log
➁ Shows the commits on branchA that are not on branchB.
❯ git log branchB..branchA
➊➊ git checkout
It is used to switch to another branch.
βž€ Switch to another branch and, check it out in your working directory
❯ git checkout [branch-name]
➁ Switch to another branch (create if does not exist)
❯ git checkout -b [branch-name]
βžŠβž‹ git merge
βž€ Join 2 or more development histories together.
❯ git merge [branch]
➊➌ git fetch
βž€ Fetch branches and/or tags from one or more other repositories.
❯ git fetch [alias]
✧ Note: You can use git fetch to know the changes made in the remote repo/branch since your last pull.
➊➍ git pull
βž€ Fetch and merge any commits from the tracking remote branch.
❯ git pull
➊➎ git push
βž€ Transmit local branch commits to the remote repository branch.
❯ git push [alias]
➊➏ git rebase
βž€ Applies any commits of the current branch ahead of the specified one.
❯ git rebase [branch-name]
➊➐ git revert
βž€ Reverts some existing commits.
❯ git revert <commit>
βžŠβž‘ git reset
Resets current HEAD to the specified state.
βž€ Unstages a file while retaining the changes in the working directory.
❯ git reset [file]
➁ Clears staging area and rewrites working tree from specified commit.
❯ git reset --hard [commit]
βžŠβž’ git stash
Temporarily stores modified, tracked files to change branches
βž€ Save modified, staged changes
❯ git stash
➁ List StackOrder of stashed file changes
❯ git stash list
βž‚ Write working from top
❯ git stash pop
βžƒ Discard changes from top
❯ git stash drop
20. git reflog
βž€ See reference logs (reflog) of HEAD for recent commits, pulls, reverts etc.
❯ git reflog
➁ Get a complete reflog of all refs
❯ git reflog show --all
βž‚ To see the reflog for a specific branch
❯ git reflog show branchA
βž‹βžŠ git config
βž€ Configures user information used across all local repositories.
❯ git config --global user. name β€œusername”
❯ git config --global user. email β€œemail”
➁ To create an alias command
❯ git config --global alias.alc β€œ!git add -A && git commit -m”
Git has become so essential that you'll never regret learning it. I hope all of these commands make it easier for you to use Git.
1. Follow me @swapnakpanda for development-related regular threads.
2. If this is useful, retweet the below tweet.

Loading suggestions...