
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.
Here’s a list of fundamental Git commands with simple definitions to help you get started with version control in Bitbucket.
Command | Easy Definition |
git init | Initialize a new Git repository |
git clone <repository-url> | Copy an existing repository locally |
git status | Show modified and untracked files |
git branch | List all branches in the repository |
git branch <branch-name> | Create a new branch |
git checkout <branch-name> | Switch to an existing branch |
git checkout -b <branch> | Create and switch to a new branch |
git add <file> | Stage a specific file for commit |
git add . | Stage all modified files for commit |
git commit -m "message" | Save changes with a commit message |
git push origin <branch> | Upload local changes to Bitbucket |
git checkout main | Switch back to the main branch |
git merge <branch-name> | Merge changes into another branch |
git pull origin main | Fetch latest changes from the remote repository |
git push origin --delete <branch> | Delete a remote branch from Bitbucket |
rm .git | Remove git repository setup from your project |
Here is the step-by-step process of using Git with Bitbucket:
Screenshot 1.1a
Navigate inside your project directory - Use the following command to change the directory: (Refer to the screenshot for your reference)
Screenshot 1.1b
PLEASE NOTE: Step 1 is commonly used to reach the respective project directory and start using all Git commands (e.g., git init, git status, git add, git commit, git push, git pull, git branch, git checkout, git clone, git log)
Screenshot 1.2
Great! You have successfully initialized your first git repository for your current project
Note:
The following screenshot shows the Bitbucket workspace overview. After logging in to Bitbucket, you will see this page.
Screenshot 1.3
Go to the repositories section, then select the corresponding project to clone.
Screenshot 1.4
Once you have selected the corresponding project, you will see the following screen. In the top right corner, there is a Clone button. Click that.
Screenshot 1.5
This below pop-up will appear, where you can copy the link for further use.
Screenshot 1.6
Let's start the execution of the clone command:
Screenshot 1.7
Screenshot 1.8
Note: Once the cloning process is completed, you can check the cloned repository in your local directory.
Great! You have successfully cloned the repository from Bitbucket to your local machine.
Definition: View modified, staged, and untracked files in the repository.
Screenshot 2.1
Note:
Screenshot 2.1a
b. On branch development: This tells you that you're currently on the development branch.
Screenshot 2.1b
c. Nothing to commit, working tree clean: This means no changes have been made to tracked files, and there’s nothing new staged for commit.
Screenshot 2.1c
Great! You have successfully checked the status of changes in your repository.
Screenshot 2.2
Note:
Great! You have successfully staged the specific file for commit.
Screenshot 2.3a
Screenshot 2.3b
Note: Here, . (dot operator) means all the modified files in the current directory.
Great! You have successfully staged all modified files for commit.
Screenshot 2.4
Note: Replace "Message" with your descriptive commit message. Here, I used Initial Commit as my message during the commit.
Other way to commit in VS Code: On the left sidebar, click on the Source Control icon (it looks like a branch). You’ll see a list of Changes that includes modified files, staged changes, and untracked files.
Screenshot 2.5
Click on "Yes" to stage all your changes and commit them directly.
Screenshot 2.6
Great! You have successfully committed the staged changes with a message.
Note: The terminal will display all the branches available in your repository
Screenshot 3.1
Note: If no branches have been created yet (e.g., in a newly initialized Git repository), this command will not output anything. In that case, make a commit and try the command again.
Screenshot 3.2
If the repository was cloned from Git, then the screenshots will look like the one below.
Screenshot 3.3
Screenshot 3.4
Great! You have successfully listed all branches in your repository.
Screenshot 3.5
Note:
Screenshot 3.6
To switch to the newly created branch, Use the command: git checkout <branch-name>
Screenshot 3.7
Great! You have successfully created and switched to a new branch in your repository.
Screenshot 3.8
Note: Replace <branch-name> with the name of the branch you want to switch to. Here development is my branch name.
Great! You have successfully switched to the new or existing branch in your repository.
Screenshot 3.9
Note: Replace <branch-name> with the desired name of your new branch. Here main is my current branch name.
Great! You have successfully created and switched to a new branch in your repository.
Screenshot 4.1
Note: The current branch will be highlighted with an asterisk (*)
Great! You have successfully checked the current branch you are working on.
Screenshot 4.2
Here, You can check the current remote verbose (detailed information about the remote URL)
Screenshot 4.3
Now, execute the push command as shown below:
Screenshot 4.4
Note: Replace <branch-name> with name of the branch you want to push your changes to. Here, development is my current branch to push your changes.
Other case, If the remote isn't configured or is incorrect, then you will get the following error
Screenshot 4.5
Note:
If the remote isn't configured or is incorrect, you need to add or update the remote URL. To add a remote repository (if you haven't done so already), run the following command:
git remote add origin <repository-url>
Then, to push the changes to the remote repository, run:
git push -u origin <branch-name>
Note: Replace <repository-url> with the URL of your remote repository (e.g., https://github.com/username/repository.git for GitHub, or https://bitbucket.org/username/repository.git for Bitbucket).
As shown in (Screenshot 4.2), you may be unsure of how to obtain the <repository-url>. To do this, go to Bitbucket, click on Create → Repository
Screenshot 4.6
The following page will open. Enter the repository name (test_app_ui), set the access level to either private or public, choose the default branch name as master, and click Create Repository.
(Note: The workspace has already been created by the Bitbucket administrator, and the project will be selected from the dropdown menu.)
Screenshot 4.7
After this, you can see the Bitbucket repository under your workspace/project name.
Screenshot 4.8
As usual, click on the Clone button at the top right, and you will see the repository link.
Note: Avoid using git clone and .git. Only use the central part of the repository URL. Refer to the screenshot before running the command.
Screenshot 4.9
Great! You have successfully pushed your changes to the remote repository
Note: Add reviewers and request feedback.
Screenshot 5.1
Screenshot 5.2
Screenshot 5.3
Screenshot 5.4
Step 6: Add reviewers who should review your changes.
Screenshot 5.5
Screenshot 5.6
Note: Replace <branch-name> with the desired name of your new branch
Great! You have successfully created a Pull Request (PR) on Bitbucket. Reviewers will now be able to provide feedback and approve the merge.
Screenshot 6.1
Great! You have successfully switched to the main branch in your repository.
Screenshot 6.2
Note: Replace <branch-name> with the name of the feature branch you want to merge. Here development is another branch
Great! You have successfully merged the feature branch into the main branch.
Screenshot 6.3
Great! You have successfully pushed the updated main branch to Bitbucket.
Screenshot 7.1
Note: Replace <branch-name> with the name of the branch you want to delete. In this case, development is the branch that I want to delete.
⚠ Warning: Deleting a local branch is irreversible. Ensure it has been merged and is no longer needed before deleting.
Great! You have successfully deleted the merged local branch from your repository.
Screenshot 7.2
Note: Replace <branch-name> with the name of the branch you want to delete
⚠ Warning: Deleting a branch from Bitbucket is permanent and cannot be undone. Ensure the branch is no longer needed before proceeding.
Great! You have successfully deleted the remote branch from Bitbucket.
Screenshot 8.1
Note: Be cautious when using this command, as it permanently deletes all Git tracking and history for the project. Once executed, you cannot recover the Git information unless you have a backup.
Great! You have successfully uninitialized the Git repository for your project.
If you want to publish the branch, then click the "Publish Branch" button in the source control panel (you'll see it in the Source Control view). If you're not already logged into GitHub, Visual Studio Code will prompt you to sign in - A popup will appear asking you to allow access to your GitHub account.
Publish Branch - Screenshot 1
Click Allow, and it will redirect you to the GitHub login page.
Publish Branch - Screenshot 2
Enter your GitHub credentials or authorize via GitHub if you've already set up the connection. After successful authentication, the branch will be pushed to GitHub.
Publish Branch - Screenshot 3
If you want to this option may appear as something like "Sign in to Bitbucket" or "Connect to Bitbucket" on the left sidebar or in the application’s menu.
Publish Branch - Screenshot 4
After you click the sign-in option, a page or popup should appear asking you to log in to Bitbucket Cloud. Click on "LOGON TO BITBUCKET CLOUD" (or something similar).
Publish Branch - Screenshot 5
Click Allow, and it will redirect you to the GitHub login page.
Publish Branch - Screenshot 6
If you are already logged in, the connection will be established automatically, and you should see your Bitbucket account listed in your Git GUI.
Publish Branch - Screenshot 7
If you aren’t logged in already, you will be prompted to enter your Bitbucket credentials (username and password) or use an OAuth token (if Bitbucket 2FA is enabled). After entering the credentials, try clicking Log In or Authorize to connect the account.
After logging in and providing your credentials, your Bitbucket account will be linked to the VS Code You can then push, pull, and manage repositories directly from the Git GUI.
A structured Git workflow ensures smooth collaboration and efficient version control. Below is the recommended workflow to follow when working with Git and Bitbucket.
Workflow Diagram 1.1
Workflow Diagram 1.2
When using Git and Bitbucket:
✔ Always write clear commit messages.
✔ Follow your team's branching strategy.
✔ Keep your local repository updated.
✔ Avoid committing sensitive information (API keys, passwords).
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 enhances your version control knowledge.
If you found this helpful, feel free to share your thoughts, feedback, or questions in the comments! Let's keep learning and growing together. 🚀
Stay tuned for Part 2, where we’ll explore more advanced Git commands!
Happy coding! 💻✨ 😊
This is my first blog, so experts, please feel free to correct me if any information is inaccurate. Thanks in advance 😊
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |