Category Archives: Git

Learn Git with DevOpsRoles.com. Access in-depth guides and tutorials to master version control and improve your DevOps workflow using Git.

Install git from source Centos 6

In this tutorial, How to install Git from source Centos 6. Git the essential for DevOps Roles. 

To install Git from source on CentOS 6, you can follow these steps:

Install git from source Centos

Update System Packages:

Install “Development Tools” for Centos 6.

$ sudo yum -y groupinstall "Development Tools"

To install the package prepare git

$ sudo yum install -y gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel curl-devel expat-devel openssl-devel gcc perl-ExtUtils-MakeMaker

Downloading Git from source link the latest here. I use git version 2.18.

$ wget https://www.kernel.org/pub/software/scm/git/git-2.18.0.tar.gz

Decompress and install Git from the source

$ tar xzf git-2.18.0.tar.gz
$ cd git-2.18.0
$ make configure
$ ./configure
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
$ git --version

You should see the Git version displayed if the installation was successful.

Conclusion

Through the article, you can “install Git from source Centos 6” as above. You can start using Git by executing Git commands in the terminal. I hope will this your helpful. Thank you for reading the DevopsRoles page!

A Beginner’s Guide to Git Clone Repository

Introduction

In this tutorial, we will guide you on how to git clone a repository and sync it to your server. Git is a popular version control system used by developers to manage source code and collaborate on projects efficiently.

To clone a Git repository, you need to have Git installed on your system. Follow these steps to clone a repository:

Prerequisites

  • Target: gitlab repository
  • Source: Server Linux

Steps to Clone a Git Repository

1. Install Git

Ensure Git is installed on your system. If not, install it using the following command:

sudo apt-get install git

2. Clone the Repository

To create a clone or copy of the target repository on your server, use the following command:

git clone https://huupv@https://gitlab.com/DevopsRoles/devopsroles.git

3. Switch Branches

To switch from the master branch to the develop branch, use:

git checkout develop

4. List All Branches

To list all the branches in your repository, execute:

git branch

5. Fetch and Merge Changes

To fetch and merge changes from the remote server to your working directory, run:

git pull

Conclusion

By following this guide, you can successfully clone a Git repository to your local machine. You can now navigate into the cloned repository and start working with the code or files it contains. We hope this guide is helpful. Thank you for reading the DevopsRoles page!

How to install Git 2.18 on CentOS

Git is an open-source distributed version control system. In this tutorial, I will install Git 2.18 client on Centos.

CentOS’s default package repositories might not always have the latest version of Git available.

Here’s how you can install Git 2.18 on CentOS:

Jenkins release the source error code as below:

/remotes/origin/*" returned status code 128: error: The requested URL returned error: 401 while accessing https://github.com/xxx/xxx/info/refs
fatal: HTTP request failed

Solve problem Required Git >= 1.7.10

Step 1: Install the required packages

Before installing git makes sure you have installed in the package your system.

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker

Step 2: Install git on Centos

Downloading Git source code from kernel git

cd /usr/src
wget https://www.kernel.org/pub/software/scm/git/git-2.18.0.tar.gz
tar xvzf git-2.18.0.tar.gz

After extracting the git source code and compiling the source code as below:

cd git-2.18.0
make prefix=/usr/local/git all
make prefix=/usr/local/git install

Step 3: Setup Environment

After the installation completes, you might need to update your system’s PATH environment variable to include the Git binary directory. Add the following line to your shell configuration file (e.g., .bashrc, .bash_profile, or .profile):

Set the PATH variable and reload the change in the current environment

echo "export PATH=/usr/local/git/bin:$PATH" >> /etc/bashrc

To apply the updated PATH configuration, either restart your shell session or run the following command:

After completing the steps. Verify that Git has been installed correctly by running:

git --version

Conclusion

Through the article, you should be able to manually build and install Git version 2.18.0 on CentOS. However, it’s worth noting that using the package manager or a more recent pre-built version from official repositories is generally recommended for easier maintenance and updates. I hope will this your helpful. Thank you for reading the DevopsRoles page!

git command line for beginners

In this tutorial, the Git command line is for beginners, Git server is a repository. I use the command line for my project.

Git is a powerful version control system used for tracking changes in software projects. Here are some basic Git commands for beginners:

Git command line for beginners

Git global setup

 git config --global user.name "PHAN VAN HUU"
 git config --global user.email "pvhuu90@gmail.com"

To create a new repository

 cd BashScripts
 git clone https://gitlab.com/huupv/DevopsSkills.git
 touch README.md
 git add README.md
 git commit -m "add README"
 git push -u origin master

Existing my folder

 cd BashScripts
 git init
 git remote add origin https://gitlab.com/huupv/DevopsSkills.git
 git add .
 git commit -m "Initial commit"
 git push -u origin master -f

Existing git my repository

 cd BashScripts
 git remote rename origin old-origin
 git remote add origin https://gitlab.com/huupv/DevopsSkills.git
 git push -u origin --all
 git push -u origin --tags

I explained the commands below

Git current state

How to list which (unstaged) files have changed, Shows the current status of the repository, including modified and untracked files.

git status

How to list (unstaged) changes to files: (Shows the differences between the working directory and the staging area)

git diff

How to list recent commits: (Displays the commit history of the repository)

git log

Tell me who you are:

git config --global user.name "PHAN VAN HUU"
git config --global user.email "pvhuu90@gmail.com"

To create a new local repository:

git init

To check out a repository

To create a working copy of a local repository

git clone https://gitlab.com/huupv/DevopsSkills.git

For remote server

git clone huupv@host:/path/to/repository

How to add files:

git add File_Name

To commit change but not yet to the remote repository:

git commit -m "Add file to repository commit"

To commit any file with git add:

git commit -a

How to “push” send changes to the master branch of your remote repository:

git push origin master

How to connect to a remote repository:

git remote add origin https://gitlab.com/huupv/BashScripts.git

How to list all currently configured remote repositories:

git remote -v

For Git branches

To create a new branch and switch to it:

git checkout -b <branchname>

To switch from one branch to another:

git checkout <branchname>

To list all the branches in your repository:

git branch

To delete the branch:

git branch -d <branchname>

To push all branches to your remote repository:

git push --all origin

To delete a branch on your remote repository:

git push origin :<branchname>

How to fetch and merge changes on the remote server to your working directory:

git pull

The conclusion

Thought the article, To help you understand the git command line. Thanks for reading my “git command line” post. I’m updating more useful commands line for Git. Thank you for reading the DevopsRoles page!

How to Gitlab SSH key pair

Introduction

In this guide, We’ll explore how to use gitlab SSH keys for Git operations in your projects. Learn the step-by-step process to generate an SSH key pair for GitLab and integrate it with your account.

To effectively use GitLab via SSH, you must create an SSH key pair and link the public key with your GitLab account.

How to do Gitlab SSH key pair

Open a terminal on your Linux system.

If you do not have an SSH key pair, then the error message is as below:

$ cat ~huupv/.ssh/id_rsa.pub
 cat: /home/huupv/.ssh/id_rsa.pub: No such file or directory

To generate a new ssh key pair by running the following command

$ ssh-keygen -t rsa -C "huupv@devopsroles.com" -b 4096

Replace “huupv@devopsroles.com” with your actual email address associated with your GitLab account. You can press Enter to accept the default file path and passphrase (or set a passphrase for added security).

The output Gitlab SSH key pair is below

Generating public/private rsa key pair.
 Enter file in which to save the key (/home/huupv/.ssh/id_rsa):
 Created directory '/home/huupv/.ssh'.
 Enter passphrase (empty for no passphrase):
 Enter same passphrase again:
 Your identification has been saved in /home/huupv/.ssh/id_rsa.
 Your public key has been saved in /home/huupv/.ssh/id_rsa.pub.
 The key fingerprint is:
 2a:16:6d:94:35:a2:02:db:2c:ce:fb:4f:79:56:bf:0b huupv@devopsroles.com
 The key's randomart image is:
 +--[ RSA 4096]----+

To generate 2 files as below:

Private key: id_rsa
Public key: id_rsa.pub

I already have ssh key pair to create on my laptop.

$ cat ~/.ssh/id_rsa.pub

The content public key id_rsa.pub is as below:

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAwEts938rLe7B1KKgYYBrhCMHFzeumk1IaoVo3rD48qVCig8fCHvp+W3Z2UzHHS9iT1IscXi0Bxq+/fTO9cbB5EznGTIW3I7y26yzIq/6iv3I/biYMmi6EiWCd2Ed2188uZ9aR0+gN4QIAmU8Grh91eaEy04d9H67GF2UT3lqx3PEi7v7aIH6FdkCdOp2YIE25UTuJoMoZ3kjKo02tGP7y/PUw8lbm/ezvYFLBN5l5DfmebDwSBNrR/K84mLWGx3L/bB9XnkEZRSh2vi+YFQ5FMomJA8+RHzfUS5zV3tI8VFDe1bGvcpYxKLKGc1bfKBZSYsOpsKgOofBcENaOJ8l0xCLWMFbJkAKcLEFuwBpLTx75WF7MEaxBnEIWekhhBR5hC+cR2fKEYuZaOYmpBfZUGnIDadad83+3qOQs+50/11AoinHCBOEphWRbn6pk0JP+pyTDsRKEmZ4KNOJt/WNwfVMnCVKb/5wcwCrmQ8ztWilcjT0UdMYUoH4u2IidWV5F38vAdG+LNH5dmKr2pcI7CdgZSXQqppkrvcqMLeH2BprlxuJW8qLc1hYV6HhWYbJc3EX28a6mZfohXLQAgN8HVpBaQ9UAZ33MiDPUhHeIW1OeXSXQHgH5t0CjXqzg3G9/vM7qOUr/27kN+D0ExBPENQf7hZ5Aw24fJl/PLQHAHs= huupv@devopsroles.com

Copy and paste the content id_rsa.pub to the Profile Settings in the Gitlab server web interface. ( step by step as below)

Copy the ssh key to GitLab

Copy the contents of the public key by running the following command: cat ~/.ssh/id_rsa.pub

  1. Copy the entire public key output from the terminal.
  2. Now, log in to your GitLab account using a web browser.
  3. In the top right corner, click on your profile picture and select “Settings.”
  4. From the left-hand side menu, click on “SSH Keys.”
  5. Paste the copied public key into the “Key” field.
  6. Optionally, give a recognizable “Title” to the SSH key (e.g., “My Linux Workstation”).
  7. Click on the “Add key” button to save the SSH key to your GitLab account.
  8. The SSH key is now added to your GitLab account, and you can use SSH to interact with GitLab repositories.

To test the SSH key connection

You can run the following command in the terminal:

Conclusion

Throughout this article, we’ll guide you on how to set up and use an SSH key pair for your project. You’ll learn the straightforward steps to generate an SSH key pair that secures your account. This essential setup enhances the security of your project by ensuring that only authorized users can access it. Follow along to easily create and implement your SSH keys.

You are now ready to use your GitLab SSH key for secure interactions with your repositories. Thank you for reading the DevopsRoles page!

How to install GitLab on Linux

In this tutorial, How to install Gitlab on Linux such as centos server and ubuntu server. To use Gitlab CE or Community Edition is open source. It’s a Git repository, a Gitlab server like a GitHub server. The commands as below running root account.

The steps for installing the Gitlab server are as below:

  • SSH client connects to Gitlab server
  • To install the package dependencies and install Gitlab CE
  • The firewall has to open a port for the GitLab server

The hardware requirements for the Gitlab server:

  • 2 cores4GB
  • of RAM

Gitlab on Centos server

Update System Packages and Install Dependencies for the Centos server.

Open a terminal

Install them by running the following command:

# yum update -y
# yum install curl openssh-server postfix -y

Note: During Postfix installation, select Internet Site when prompted.

To install GitLab CE on the Centos server

# cd /opt/
# curl -O https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh
# sh script.rpm.sh
# yum -y install gitlab-ce
# gitlab-ctl reconfigure

Gitlab on the Ubuntu server

Update and install package dependencies for the Ubuntu server

# apt-get update -y
# apt-get install curl openssh-server postfix -y

Note: During Postfix installation, select Internet Site when prompted.

To install GitLab CE server on the Ubuntu server

# cd /opt/
# curl -O https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
# bash script.deb.sh
# apt-get install gitlab-ce
# gitlab-ctl reconfigure

How to change password root default for Gitlab server. The problem is when you first login “Invalid login or password” on the Gitlab server. This problem is solved!

# gitlab-rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=123456789

The finish, To install GitLab CE Server, the first login
From the browser you access to links:  “http://gitlab_domain_or_IP” and then login with a “root” user and with the initial password “5iveL!fe. (in this tutorial, the changed password for root is 123456789)

To restart the service for the Gitlab server

# gitlab-ctl restart

The output below:

 ok: run: gitaly: (pid 18182) 1s
 ok: run: gitlab-monitor: (pid 18190) 0s
 ok: run: gitlab-workhorse: (pid 18193) 1s
 ok: run: logrotate: (pid 18201) 0s
 ok: run: nginx: (pid 18210) 0s
 ok: run: node-exporter: (pid 18212) 0s
 ok: run: postgres-exporter: (pid 18232) 0s
 ok: run: postgresql: (pid 18241) 0s
 ok: run: prometheus: (pid 18251) 0s
 ok: run: redis: (pid 18256) 1s
 ok: run: redis-exporter: (pid 18261) 0s
 ok: run: sidekiq: (pid 18273) 0s
 ok: run: unicorn: (pid 18278) 1s

To check the status of Nginx

# gitlab-ctl status nginx

The output below:

 run: nginx: (pid 18210) 55s; run: log: (pid 12818) 2487s

Conclusion

Through this article, you have installed GitLab server on Linux with distros centos or ubuntu server.

You have successfully installed GitLab on Linux. You can now create users, and repositories, and start using GitLab for your version control needs.

I hope this will be helpful for you! Thank you for reading the DevopsRoles page!