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:
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
β 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]
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 .
β 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]
β 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]
β 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"
β 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]
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
β 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
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
β 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]
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]
β 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.
β 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
β 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]
β 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]
β 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>
β 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]
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
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
β 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β
β 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.
1. Follow me @swapnakpanda for development-related regular threads.
2. If this is useful, retweet the below tweet.
Loading suggestions...