Deleting a local git branch is easy, using options `-d` or `-D` will do it. Its is always safe to use `-d` option because it won’t allow us to delete unmerged branch, where as `-D` will delete the unmerged branch without any warning or notification.
git branch -d branch_name_to_delete
But this will delete only branch in our local system.
Delete remote branch
So how can we delete a remote branch? Any way none of the option for git branch won’t delete it. Remote branch can only deleted by using git push command.
git push origin :branch_name_to_delete
You have to notice the full-colon (:) prefixed to the branch name. The prefixed colon is the one asking git to do the trick.
Have you ever had a typo in your git commit message and thought of editing it?
Have you ever thought of small change in code which should be merged to last commit?
Then this post will help you to edit commit message in git or add some more changes into the previous git commit, provided you haven’t pushed the commits to remote repo. One more thing to keep in mind that you can use this tip only on HEAD commit.
The – -amend option for git commit will help you to do it. According to the git help commit it is an equivalent for
$ git reset --soft HEAD^
$ ... do something else to come up with the right tree ...
$ git commit -c ORIG_HEAD
If you want to edit the commit message of the HEAD commit
If you want that commit to include the changed files use git add before using the above command
While working on a project, I was unable to configure git on the shared host. It was a nightmare to upload only the changed files after a bug fix. Keeping track manually on all the changed files got failed. So I started searching for a easy solution and I end up with a script which I can copy the changed files between two commits with directory structure.
In this I only need to keep track of the last uploaded commit, which seems to be easy for me. You just need to save the below script to git-copy.sh file and keep in the root folder of the project. Don’t forget to give execute permission for the file.
How to Use
This script accepts three parameters.
The Hash of First commit
The Hash of second commit
The destination folder, where we need to copy the files.
Have you ever thought that it should be good if the git output in your terminal is colourful? ie.,
Added files in one colour
untracked files in some other colour
Added lines and deleted line is differentiated with colour
Here is the simplest way you can achieve it. Just run the following command after changing the directory into project directory/git repository
This will show the git output in colour, only for this specific git repository. If you need the same for all git repository then you should run
Now check your git output. It will be colourful and you will find really easy to differentiate the added and untracked files. Try git diff, you will find even more easier to find the added and deleted line.
Where Am I?
You are currently browsing the git category at