Git with Bitbucket
Suppose you are working on a project that will have different versions during the development time. The best way to keep track with the different versions is using Bitbucket. You can create separate branches where you can keep the project versions in it and access it from the local machine. It’s a procedure where you can have the same files in the local machine as well as in the Bitbucket. You just need to write some command in the terminal and voila!!, it’s working. You need to have git in your system at first to work with the Bitbucket.
Now, let see how we can work with the Bitbucket. It’s pretty simple. You need to create a repository first. Go to this link:
After you created your account, you will see a plus sign in the left bar, click it and make repository. You can keep the repository private or public. It’s your privilege. If you set it to public then anyone can access it and in case for private, only you can access the repository. Now, it’s time to learn the rest. At first create a new folder in your desktop and open your terminal from that folder directory to write the following command:
git clone https://emmap1@bitbucket.org/emmap1/bitbucketstationlocations.git
This command will clone the repository in your local machine. Now about the https link, wow wait where that came from? No worries, it’s simple. Go to the overview section of your repository and you will find two links. It’s both https and SSH links. Copy and past that link after writing git clone, and it will clone you repository all ready. Now what does mean “clone”, right? It means it will retrieve all the contents from that repository to your local machine folder’s directory where you are working on. Now you can work with clone version repository and it doesn’t affect the Bitbucket repository until you change it writing another function in the terminal.
To see the progress in your repository:
git status
This command will show you the changes have been made in the repository to keep track.
Now, suppose you want to create a file. Write this command.
echo “I am someone” >> locations.txt
This will create a file name locations.txt with the content of “I am someone” but it is untracked to git and you need to tell the git to track your new file. You will see this message by writing “git status” command. Now tell the git to track your new file by writing this command:
git add locations.txt
Your new file has been added in the git and it’s ready to commit. Commit by the following command:
git commit –m ‘initial commit’
You have committed the file with a message “initial commit”. Now commit means there has been some changes in your repository and it’s ready to go in the Bitbucket and you can do that by simply writing this command:
git push origin master
Here, master is your main branch that means there is no other branch is created yet.
Suppose there has been some changes in your Bitbucket repository and you want those changes in your local repository. Simple, write this command:
git pull — — all
Now, let’s create a new branch in the repository.
git branch tutorial
This command will create a new branch named as tutorial. Now there is two branch. One is master and another is tutorial.
But initially you will be in master branch and if you want to change branch, just simply write this command:
git checkout tutorial
It will change the branch directory to the tutorial branch. And you can work as long as with that branch make changes as well as push them in the Bitbucket.
To merge the new branch into the main branch, write the following command:
git merge tutorial
Now both branch will be just act like one branch and that will be master branch.
If you want to delete a branch:
git branch -d tutorial
New branch will be deleted and only branch remaining is master branch.
If you have an existing repository then follow these step to upload the repository in the Bitbucet. In order to upload the project, you have to change the directory to that existing repository in CMD.
- git init : git initialization.
- git add — all
- git remote add origin https://emmap1@bitbucket.org/emmap1/bitbucketstationlocations.git
- git commit -m “my first commit”
- git push -u origin master
It will upload the existing repository in the Bitbucket. :D
So, this is the basic of “Git with Bitbucket” and you can work with the Bitbucket with these simple commands and keep track your projects. Best practice of working with the git is writing “git status” and keep track your changes. I hope you like this tutorial. If you do have any suggestions then please do comment and let me know. It would be helpful for me in the future to write a better tutorial.
Thanks!