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]:
- 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.
- 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.
- 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]:
- Go to your HOME directory in your linux machine:
cd ~ - Type the following command at the terminal
ssh-keygen - The command will prompt you to save the file under the location <HOME_Directory>/.ssh/id_rsa.
- Press enter to select the default location.
- The command will prompt for passphase. Press enter to provide blank passphase.
- 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]:
- Click on your bitbucket avatar icon, and go to Bitbucket settings.
- Under Security, go to SSH keys.
- Click on the Add key, provide a label.
- Copy the contents of your public key (i.e. ~/.ssh/id_rsa.pub) and paste it in the text box “Key”.
- Click on the add key, and you are done.
Steps to create repository in Bitbucket[5][6]:
- From Bitbucket, click the Create button at the top of the page and select Create repository from the drop-down menu.
- Provide the name of the repository, say myrepo, in the Name field.
- Provide the description of the repository in the Description field.
- For Access Level, select the check-box to make the repository private, otherwise un-select it.
- Select Git for repository type. Note, repository type cannot be changed later.
- Check both Issue tracking and Wiki checkbox for Project Management.
- For language field, select the option of your choice.
- 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:
- Find the repository URL from the Overview Page.
- Select the SSH option, the URL will look similar to “ssh://git@bitbucket.org/username/reponame.git”.
- 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:
- https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
- https://git-scm.com/docs/git-config
- https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
- https://confluence.atlassian.com/bitbucket/create-a-git-repository-759857290.html
- https://confluence.atlassian.com/bitbucket/create-a-repository-221449521.html