Setup Git in Fedora 23 with Bitbucket

Git Installation in Fedora:

Command to install Git:

sudo dnf install git-all

Basic Git configuration:

For complete details of git configuration refer to [2][3]. To start with it is good to configure the user name and email id, which can be done as follows:

git config –global user.name “John Doe”
git config –global user.email johndoe@example.com

The above two command will configure the user-name and email-id at global level.

Following are the 3 levels of configuration which are also described in detail in [2]:

  1. System Level (comman for all user): /etc/gitconfig file: Contains values for every user on the system and all their repositories. If you pass the option –system to git config, it reads and writes from this file specifically.
  2. User Level (comman for all git repositories): ~/.gitconfig or ~/.config/git/config file: Specific to your user. You can make Git read and write to this file specifically by passing the –global option.
  3. Repository Level (specific to particular repository): config file in the Git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository.

To check the git configuration:

git config –list

Check for already exisiting SSH keys[4] in the system:

Check if a pair of public private key already exist, by running the command:

cd ~/.ssh/
ls id_*

If you get files, then the keys already exist, no need to generate new SSH keys. Else continue to next step to generate new SSH keys.

Generating a new SSH key for secure connection[4]:

  1. Go to your HOME directory in your linux machine:
    cd ~
  2. Type the following command at the terminal
    ssh-keygen
  3. The command will prompt you to save the file under the location <HOME_Directory>/.ssh/id_rsa.
  4. Press enter to select the default location.
  5. The command will prompt for passphase. Press enter to provide blank passphase.
  6. The private key (id_rsa) and public key (id_rsa.pub) files will be generated.

Bitbucket Setup:

Create an account in Bitbucket.

Add the public key to the Bitbucket[4]:

  1. Click on your bitbucket avatar icon, and go to Bitbucket settings.
  2. Under Security, go to SSH keys.
  3. Click on the Add key, provide a label.
  4. Copy the contents of your public key (i.e. ~/.ssh/id_rsa.pub) and paste it in the text box “Key”.
  5. Click on the add key, and you are done.

Steps to create repository in Bitbucket[5][6]:

  1. From Bitbucket, click the Create button at the top of the page and select Create repository from the drop-down menu.
  2. Provide the name of the repository, say myrepo, in the Name field.
  3. Provide the description of the repository in the Description field.
  4. For Access Level, select the check-box to make the repository private, otherwise un-select it.
  5. Select Git for repository type. Note, repository type cannot be changed later.
  6. Check both Issue tracking and Wiki checkbox for Project Management.
  7. For language field, select the option of your choice.
  8. Click “Create repository” button to create the repository.

Initialize a git repository and point it to your Bitbucket repository.

mkdir /path/to/your/project
cd /path/to/your/project
git init
git remote add origin ssh://git@bitbucket.org/username/reponame.git

Check your repository specific git configuration:

  • To check repository specific git configuration run following commands:

cd /path/to/your/project
cat .git/config

  • Check if the repository url is using HTTPS protocol as shown below:

[remote “origin”]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://emmap1@bitbucket.org/emmap1/bitbucketspacestation.git

  • Change repository url format from HTTPS protocal to SSH protocol:
  1. Find the repository URL from the Overview Page.
  2. Select the SSH option, the URL will look similar to “ssh://git@bitbucket.org/username/reponame.git”.
  3. Change the repository url value to SSH format “ssh://git@bitbucket.org/username/reponame.git” using your favourite file editor, so that it looks like below:

[remote “origin”]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://git@bitbucket.org/username/reponame.git

To set remote master as default branch for push and merge while pull, run following commands:

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

To set the default git push as upstream [3]:

git config –global push.default upstream

References:

  1. https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
  2. https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
  3. https://git-scm.com/docs/git-config
  4. https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
  5. https://confluence.atlassian.com/bitbucket/create-a-git-repository-759857290.html
  6. https://confluence.atlassian.com/bitbucket/create-a-repository-221449521.html

Leave a comment