Introduction
In Part I of this series, we explored the basics of Git and its role in version control. Building on that foundation, this blog (Part II) focuses on using Git commands with Bitbucket.
Git is a powerful version control system that helps developers track changes, collaborate efficiently, and manage project versions. It enables teams to work simultaneously on different features, maintain code history, and revert changes when necessary. When working with Bitbucket, Git commands allow you to clone repositories, create branches, commit changes, and push updates seamlessly. Bitbucket also offers features like pull requests, code reviews, and integrations with CI/CD pipelines to enhance development workflows.
In this blog, we’ll cover the fundamental Git commands required to work with Bitbucket, along with simple definitions to help developers at all levels understand and use them effectively. Whether you're a beginner or an experienced developer, mastering these commands will help you streamline your version control process.
10 Intermediate Git Commands for Bitbucket
These are an intermediate Git commands will help you manage your repository more efficiently, collaborate better, and handle more complex workflows with Bitbucket.
Command | Easy Definition |
git log | View the commit history in your repository |
git show <commit> | Show detailed information about a specific commit |
git diff | Compare changes between working directory and last commit |
git reset --soft HEAD~1 | Undo the last commit but keep changes staged |
git reset --hard HEAD~1 | Completely undo the last commit and discard changes |
git revert <commit> | Create a new commit that reverses a specific previous commit |
git stash | Temporarily save uncommitted changes |
git stash pop | Re-apply stashed changes back into your working directory |
git tag <tagname> | Create a lightweight tag for a specific commit |
git remote -v | View all remote repositories linked to your project |
Prerequisite: Opening the Terminal
In general, please follow the steps below to open the terminal:
- Step 1: Go to your Terminal -> New Terminal
Screenshot 1.1
Navigate inside your project directory - Use the following command to change the directory: (Refer to the screenshot for your reference)
- cd.. means Changes to the parent directory
- cd <project-directory> means Changes to the specified project directory
Screenshot 1.2
PLEASE NOTE: Step 1 is commonly used to reach the respective project directory
Next, let’s explore the commands:
🔹View commit history:
- Definition: View the commit history of your repository, showing detailed information about past commits, including timestamps, author, and commit messages.
- If you want to view the commit history in your repository, Run the command: git log
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git log and press Enter
Screenshot 2.1
Note: You can press q to exit the git log view and return to the command prompt.
Great! You have successfully viewed the commit history of your repository.
🔹Display details of a specific commit
- Definition: Show detailed information about a particular commit, including the changes made and the files affected.
- If you want to see information about a specific commit, Run the command: git show <commit-hash>
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git show <commit-hash> and press Enter
Screenshot 3.1
Note: Replace <commit-hash> with the actual commit ID you want to inspect. Refer Screenshot 3.2 for better understanding.
Go to your project folder in Bitbucket, select your working branch, and choose the commit number you want to inspect. In this example, ea03bc2 is one of my commit hashes that I used for checking.
Screenshot 3.2
Note: Make sure to copy the full commit hash or at least enough characters to uniquely identify the commit.
Great! You have successfully displayed the details of a specific commit.
🔹Compare changes in your working directory
- Definition: Compare the current state of your working directory with the last commit to view what changes have been made.
- If you want to compare the changes made to files since the last commit, Run the command: git diff
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git diff and press Enter
Screenshot 4.1
Note:
- Use git diff to review changes before staging or committing them.
- Remember, this only shows unstaged changes; to see staged changes, you can run git diff --cached
- If no output appears, it means there are no changes to display.
Awesome! You have successfully compared changes in your working directory.
🔹Undo the last commit but keep changes staged
- Definition: Undo the most recent commit while keeping your changes staged for a new commit.
- If you want to undo the last commit but retain changes, Run the command: git reset --soft HEAD~1
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git reset --soft HEAD~1 and press Enter
Screenshot 5.1
Before and after running the command, your Source Control section will look as shown below.
Screenshot 5.2
Note:
- The git reset --soft HEAD~1 command removes the last commit but keeps all your changes staged, ready for you to edit or recommit. Count has been mentioned at end. Here 1 is the count, so, 1commit will be undone
- Use this when you want to update your last commit without losing any work!
Well done! You have successfully undone the last commit while keeping your changes staged.
🔹Completely undo the last commit
- Definition: Completely undo the last commit and discard the changes from both the commit and working directory.
- If you want to completely remove the last commit and its changes, Run the command: git reset --hard HEAD~1
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git reset --hard HEAD~1 and press Enter
Screenshot 6.1
Note:
- Use git log before running git reset --hard HEAD~1 to double-check the commit you are about to remove. Count has been mentioned at end. Here 1 is the count, so, 1commit will be undone
- Warning: git reset --hard permanently deletes the changes from your working directory and commit history. Once done, you cannot recover the discarded changes unless you have a backup!
Nice work! You have completely undone the last commit.
🔹Reverse a specific commit
- Definition: Create a new commit that undoes the changes of a specific commit without altering the commit history.
- If you want to revert a specific commit, Run the command: git revert <commit-hash>
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git revert <commit-hash> and press Enter
Screenshot 7.1
Then, you will see the following screen. Edit the commit message if needed, press Esc, then type :wq and press Enter to save and exit.
Screenshot 7.2
Note: If you don't want to edit the commit message while reverting, you can add the --no-edit flag to the command like this: git revert --no-edit <commit-hash>. This will automatically use the default revert message.
Go to your project folder in Bitbucket, select your working branch, and choose the commit number you want to revert. In this example, dc51c05 is one of my commit hashes that I used for checking.
Screenshot 7.3
Note:
- Replace <commit-hash> with the actual commit ID you want to inspect. Refer Screenshot 3.2 for better understanding.
- When you run git revert <commit-hash>, Git will open the default editor to allow you to modify the commit message for the revert.
- You can either edit it or simply save and close the editor to complete the revert.
Excellent! You have successfully reversed a specific commit.
🔹Temporarily save uncommitted changes
- Definition: Temporarily save changes that you haven't committed yet, so you can switch tasks without losing your progress.
- Example: To save your changes for later, Run the command: git stash
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git stash and press Enter
Screenshot 8.1
Note:
- When you run git stash, your uncommitted changes are saved in a stack-like structure.
- You can retrieve them later using git stash apply or view the list of stashes with git stash list.
Good job! You have temporarily saved your uncommitted changes.
🔹Re-apply stashed changes
- Definition: Reapply the changes you previously stashed back into your working directory.
- If you want to bring back your stashed changes, Run the command: git stash pop
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git stash pop and press Enter
Screenshot 9.1
Note:
- When you use git stash pop, the most recent stashed changes are reapplied to your working directory and the stash is automatically removed from the stash list.
- If you want to keep the stash for later use even after applying it, use git stash apply instead
Great! You have successfully re-applied your stashed changes.
🔹Create a tag for a commit
- Definition: Create a lightweight tag to mark a specific commit, often used for releases or milestones in the project.
Example: To create a tag for a commit, Run the command: git tag <tagname> - Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git tag <tagname> and press Enter
Screenshot 10.1
If someone wants an annotated tag (which is more detailed with a message, date, and author info), they would use: git tag -a <tagname> -m "your message". Here, I have created an annotated tag.
Screenshot 10.2
Once you run this command (git tag -a <tagName>), an editor will open, allowing you to add or modify the tag message.
Screenshot 10.3
You can view all the tags you have created by running the command:
Screenshot 10.4
Note:
- It's a best practice to give meaningful names to your tags, such as v1.0, release-2025, or milestone-1, so it's easy to track important points in your project history.
Awesome! You have successfully created a tag for the commit.
🔹View remote repositories linked to your project
- Definition: List all remote repositories associated with your local repository, along with their URLs.
- If you want to view all remotes for your project, Run the command: git remote -v
- Step 1: Open your terminal and navigate to the project directory (Refer Screenshot 1.1)
- Step 2: Inside your terminal, type git remote -v and press Enter
Screenshot 11.1
Note: The -v option stands for "verbose" and shows the URL of each remote repository alongside its name. This is useful for verifying where your project is pushing to and pulling from
Well done! You have successfully viewed the remote repositories linked to your project.
Thank you for taking the time to read this blog!
I hope this guide on Git commands for Bitbucket helps you streamline your workflow and deepen your version control knowledge.
If you found this helpful, I’d love to hear your thoughts, feedback, or questions in the comments. Let’s keep learning and growing together!
Stay tuned for more Git-related commands in future posts.
Dear Experts, I’m new to blogging. So, please feel free to point out any inaccuracies or suggest improvements. Thanks in advance
Happy coding!