Git : Delete remote tag

April 18th, 2014 § 0 comments § permalink

Here is how you can delete a git tag in the local and remote repo. It is pretty similar how we delete remote branch.

To delete tag locally use

git tag -d v1.0.0

To delete tag in the remote repo

git push origin :refs/tags/v1.0.0

Thats it.
Thank you.

Git : delete remote branch

January 26th, 2013 § 0 comments § permalink

Delete local branch

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.

Thanks.

Git add in patch mode

January 10th, 2013 § 0 comments § permalink

Recently I ran into a situation that I need to include only some part of changes I done to that file, but I can’t discard the rest of the changes. git add will add whole changes to the commit.

To avoid that I used git add -p . 

Git add help

-p or –patch option will iterate though each changes (hunks) in that file and ask us whether we want to stage those changes to commit.

Git add a hunk

If you wanna add this hunk reply with “y” or “n“. if you wanna check all other option please reply with “?“. A reply with “?” will return the whole help for the patch mode.

Stage the hunk

Now you can stage only the needed hunk and commit.

Happy Versioning 😉

Git : edit commit message or append changes to previous commit

April 14th, 2012 § 0 comments § permalink

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

Usage :

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

Have a happy and neat Git commits 😉

Git : copy all changed files between two commits with directory structure

April 13th, 2012 § 4 comments § permalink

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.

Syntax to execute :

./git-copy.sh hash1 hash2 path/to/destination/folder

Example :

Add colour to your git output in terminal

August 3rd, 2011 § 0 comments § permalink

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.

Happy Coding.