Setting up Git Repository for Ansible

Install DNF on the Client Side

$ dnf install git
================================================================================
 Package             Architecture  Version               Repository        Size
================================================================================
Upgrading:
 git                 x86_64        2.31.1-3.el8_7        appstream        160 k
 git-core            x86_64        2.31.1-3.el8_7        appstream        4.8 M
 git-core-doc        noarch        2.31.1-3.el8_7        appstream        2.6 M
 perl-Git            noarch        2.31.1-3.el8_7        appstream         77 k

Transaction Summary
================================================================================
Upgrade  4 Packages

Total download size: 7.6 M
Is this ok [y/N]: 

At github.com,

Do sign up for an account if you have not done so. At github.com, create a new Repository and give it a new name. Look at the pix for more information

Once you have created the repository, you should have something like this

At the profile Icon, click settings, you should enter the page where “SSH and GPG Keys” are present

Click the new SSH icon

Type the name of the key (Your Choice) and copy your ssh public keys into the key box. This can be found at ~/.ssh/id_rsa.pub or ~/.ssh/ed25519.pub. Copy the whole string and paste into the key box

Git Clone the Repository URL

Go back to your repository and copy the code

Next

At the Linux Server….

git clone the URL

$ git clone git@github.com:XXXXXXXXXX/ansible_cluster.git             
Cloning into 'ansible_cluster'...
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

At your directory go to the ansible_cluster folder, you should be able to see the README.md file which is same as your git repository.

$ cd ansible_cluster
$ cat README.md
# ansible_cluster

Setting some basic git information like user name and email address

$ git config --global user.name "user1"
$ git config --global user.email "user1@hello.com"
$ cat ~/.gitconfig
[user]
        name = melvin soh
        email = melvin@ntu.edu.sg
[init]
        defaultBranch = main

Pushing and cloning to the git repository

Let’s make some changes to the README.md

$ vim README.md
#ansible_tutorial

Hello

Checking their Status

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

Add the changes, coming and pushing the changes to git

$ git add README.md
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   README.md

$ git commit -m "Updated Readme file on 8/5/2023"
[main 06583ec] Updated Readme file on 8/5/2023
 1 file changed, 3 insertions(+), 1 deletion(-)

$ git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 308 bytes | 102.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:kittycooldew/ansible_cluster.git
   5524665..62b9b0a  main -> main

References:

  1. Top 20 Git Commands With Examples
  2. Learn Linux TV Chapter 3
Advertisement