In this tutorial we will show the steps to take to use the GIT commands to clone files from your hosting in a repository created in Bitbucket with the SSH of their cdmon hosting.
First of all, you need to have a repository created in Bitbucket. If you do not yet have it, you can access this step-by-step guide How to clone a repository and connect it to your cdmon hosting.
If you do not have any cloned repository to your ssh folder on your hosting, you will not be able to use any of these commands.
To display the commands as an example, we will create a text file and make changes with it. We will enter the folder assigned to our Bitbucket repository and launch the following command:
With this example file in the repository folder we can already show the different commands we can make to reflect changes to Bitbucket and vice versa.
GIT Commands
Mainly, there are 4 GIT commands with different uses:
git status: This command tells you the progress of the project compared to the repository in Bitbucket. For example, if you access the repository folder and run the "git status" you will see that the terminal shows a message similar to this:
The message indicates that the file is not tracked, which means that Git sees a file that does not belong to a previous confirmation. The state result also shows you the next step to follow: add the file.
git add: This command moves changes from the working directory to the Git test environment. The test environment is where you prepare a snapshot of a set of changes before confirming them in the official history.
Git should be instructed to track your new .txt file using the git add command. The git add command does not return anything when you enter it correctly.
If we do git status again, you can see that the file that you can confirm when you deem appropriate.
git commit -m: The git commit command confirms the snapshot prepared in the project history. In combination with "git add", the command we mentioned in the previous step, this process defines the basic workflow of all Git users.
This command is used to make the final confirmation. The "git commit -m" command must be entered with a confirmation message. We have executed "git commit -m Confirmation" as we show below:
At the time you first use the git commit command, the terminal will display a message like the one that appears to us on screen:
Basically, it indicates that you need to set up a name and an email address in order to apply that action. You must only copy the commands that the same message shows you and you must execute them with your respective information.
Once you have already executed both commands, you can re-release the previous command, i.e. the git commit -m with its respective confirmation message and now it must be executed correctly:
git push: To end from the terminal, we must send the confirmed changes to Bitbucket. To do this, we will use the git push command.
Once you press the Enter button again to run the command and the terminal will ask you again for the security key it has generated at the start.
We hope a little bit for you to carry out the process and you should tell us that it has ended smoothly.
To verify that it has been uploaded correctly, we are now going back to the Bitbucket dashboard, in the general configuration of the repository in question, and if we are going to the author of the request. with that of the test we have just done.
Move files created in Bitbucket to reflect in cdmon hosting
To end the tutorial, we will now show how to incorporate changes to your Git repository to see them. First of all, we will create a file in Bitbucket as a test reflected in the SSH folder of your hosting.
To add a new file, click Source to open the source directory, and then click the "More Options" button in the upper-right corner and select Add file from the menu. The More Options button only appears after adding at least one file to the repository:
A page will open for the creation of the new file. We will call it "BIT file". You must select in Syntax Mode the type of file you want to create with your respective code and give Commit to save the changes:
The Confirmation Message field appears with the default message. It can be edited if you wish or put the confirmation message you prefer.
With these steps we already have a new file in Bitbucket, now let's see how to extract these changes from the repository of our SSH.
The process is quite simple. Basically, it is about doing the procedure contrary to the shipment we did in the previous steps.
Open your terminal window and navigate to the repository directory level. In our case it is/test:
Once it is already inside the repository folder, the command you must launch is git pull -all.
The git pull command fuses your remote repository (Bitbucket) file into your local repository using a single command.
As soon as the "git pull -all" command will ask for the SSH Key password again, we put the one we have generated again:
It will take a few seconds to detect the new file, but it will finally indicate the number of files affected.
Finally, if we do a ls - we will see it that the file that has been created in Bitbucket is created in the hosting repository smoothly.
With all these steps we will have already created a repository in Bitbucket and merged it with ssh access to hosting