1. How to edit an incorrect message in Git
This is a very common question for each individuals who have just stated using Git. Suppose you have written a wrong commit message and you want to edit you can do using the following commands.
git commit --amend
It will open a editor which will allow you to change the most recent commit.
If you directly want to change the commit message, you can do using
git commit --amend -m "Edited Message"
2. How to undo the last Git commit
Suppose you accidently committed some files and you want to undo that commit. At first discard the previous commit using,
git reset --hard HEAD~1
This command will take your HEAD pointer to the 2nd last commit. After this check all the files using 'git status'. It will show you the status of the files, then you can again add the files which you want to add using git add ...
3. How to undo 'git add'
Suppose you accidentally added some files using git add but you don't want to commit those files instead want to undo those files, you can do using the below commands,
git reset <FileName> // If you want to undo a single file name
git reset // If you want to undo all due changes
4. How to delete Git Branch (Both Local and Remote)
Suppose you would like to delete a local git branch, you can use
git branch -d yourLocalBranchName
If you want to delete a Remote branch, you can use
git push origin --delete yourRemoteBranchName
5. How to delete local files in the current branch
Suppose you would like to delete all local files which you dont need to commit or to keep in your working directory, you can use the below command
git clean -f Or
git reset --hard
6. How to rename a local Git branch
Suppose you want to rename a local branch you can do using the below commands,
For current branch, git branch -m newBranchName
For other branch which you are not currently in,
git branch -m oldBranchName newBranchName
7. How to create a remote Git branch
If you want to create a remote Git branch, you can use the below commands,
git checkout -b newBranchName // to create your branch locally
git push origin newBranchName // to push new branch to your remote server
8. How to change the URL of a remote Git repository
If you want to change the URL of a remote Git Repository (say origin) you can use the following commands.
git remote set-url origin newURL
9. How to change the author name of a commit
You can modify the author info in your repository's history, you can do with this script...
git filter-branch --env-filter '
if[ "$GIT_COMMITTER_EMAIL" = "email@example.com" ]
cn="New Committer Name"
cm="New Committer Email"
if[ "$GIT_AUTHOR_EMAIL" = "firstname.lastname@example.org" ]
an="NEw Author Name"
am="New Author Email"
Above Code Taken from https://help.github.com/articles/changing-author-info
10. How to clone a repository into a specific folder
To clone a git repositor to a specific folder, you have two option
Solution 1 : Either go into that folder and type git clone URL
Solution 2 : git clone URL yourFolderName
Please Like and Share the Blog, if you find it interesting and helpful.