Home Blog

Git Tutorials - Part 2

September 28, 2018 | Ajinkya Dube |


With respect to my previous blog on basic git commands, I am listing some intermediate level Git commands.

Ref: [git-tutorials](//

1. Fetch all branched locally.

> git fetch

2. Remove a file from git repo.

> git rm {file path}

3. Remove untracked files from repo which are not in use.

> git clean -df

4. Merge branch in parent branch.

> git merge {parent branch}

5. Create a tag for a branch.

> git tab -a {Tag Name} -m {Tag Description}

6. Push local tags.

> git push origin --tags

7. Show list of previous commits.

> git log

8. Rollback to the last commit. We can use this command if we have written some unwanted code but now we don't want it. Use with precaution.

> git reset --hard HEAD

9. Rollback to a specific commit.

> git reset --haed {commit id}

10. Most dangerous: forcefully rollback to older commit of a branch. Note: Don't take pull in between 2 commands.

> git reset --hard {commit id}
> git push origin {branch name} -f

So these are some commands we can use for getting hands on git. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter or Facebook.

About the author


Ajinkya Dube

Ajinkya is an S/W Developer with good experience and always ready for any complex code. He believes in smart work than rework.