CI/CD with Dockers and Jenkins
By: Kubernetes Advocate
Tags: Tech, Startup, Docker, AWS, Architecture

GIT installation step by step

Step 0: Install git and create a GitHub account

The first two things you’ll want to do are install git and create a free GitHub account.

Follow the directions here to put in lowlife (if it’s not already installed).

Note that for this tutorial we’ll be victimization lowlife on the instruction solely.

While there are some nice lowlife GUIs (graphical user interfaces), I believe it’s easier to find out lowlife victimization lowlife-specific commands 1st and so to undertake out a git GUI

Once you’ve done that, produce a GitHub account here. (Accounts are free for public repositories, but there’s a charge for private repositories.)

Step 1: Create a local git repository

When creating a new project on your local machine using git, you’ll first create a new repository (or often, ‘repo’, for short).

If you don’t have abundant expertise with the terminal and basic commands, scrutinize this tutorial (especially the ‘Navigating the Filesystem’ and ‘Moving Around’ sections).

To begin, open up a terminal and move to wherever you wish to put the project on your native machine victimization the cd (change directory) command. For example, if you have a ‘projects’ folder on your desktop, you’d do something like:

vineet@vineet-ndi-lap-688:~$ cd Desktop/Projects/maven-project/

vineet@vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ ls

Jenkinsfile pom.xml server webapp

To initialize a git repository in the root of the folder, run the git init command:

vineet@vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ git init

Reinitialized existing Git repository in /home/vineet/Desktop/Projects/maven-project/.git/

Step 2: Add a new file to the repo

Go ahead and add a new file to the project, using any text editor you like or running a touch command.

Once you’ve added additional or changed files during a folder containing a git repo, git can notice that changes are created within the repo.

But, git won’t formally keep track of the file (that is, place it during a commit — we’ll speak a lot of regarding commits next) unless you expressly tell it to.

vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ touch website.txt

vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ ls

Jenkinsfile pom.xml server webapp website website.txt

After creating the new file, you can use the git status command to see which files git knows to exist.

vineet@vineet-ndi-lap-688:~/Desktop/Projects/maven-project$ git status

On branch master

Untracked files:

(use "git add <file>..." to include in what will be committed) Jenkinsfile

website

website.txt nothing added to commit but untracked files present (use "git add" to track)

What this primarily says is, “Hey, we tend to notice you created a brand new file known as mnelson.txt, however, unless you employ the ‘git add’ command we tend to are not reaching to do something

An interlude: The staging environment, the commit, and you

One in all the foremost confusing components, when you’re initially learning GIT, is the conception of the staging surroundings and the way it relates to a commit.

A commit could be a record of what files you’ve got modified since the last time you created a commit.

Essentially, you create changes to your repo (for example, adding a file or modifying one) so tell GIT to place those files into a commit.

Commits structure the essence of your project and permit you to travel back to the state of a project at any purpose.

So, however, does one tell GIT the files to place into a commit?

This is wherever the staging surroundings or index are available.

As seen in Step two, after you build changes to your repo, GIT notices that a file has modified however won’t do something with it (like adding it in a very commit).

To add a file to a commit, you initially ought to add it to the staging surroundings.

To do this, you’ll be able to use the GIT add the command (see Step three below).

Once you’ve used the git add a command to feature all the files you wish to the staging surroundings, you’ll be able to then tell GIT to package them into a commit

Note: The staging surroundings, additionally known as ‘staging’, is that the new most popular term for this, however, you’ll be able to additionally see it spoken because of the ‘index’.

Step 3: Add a file to the staging environment

Add a file to the staging surroundings victimization the GIT add command.

If you rerun the GIT status command, you’ll see that GIT has another the file to the staging surroundings (notice the “Changes to be committed” line).

devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git add .

devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git status

On branch master

Changes to be committed:

(use "git reset HEAD <file>..." to unstage) new file: Jenkinsfile

new file: website

new file: website.txt

To repeat, the file has not nonetheless been another to a commit, however, it is close to being.

Step 4: Create a commit

It’s time to create your first commit!

Run the command git commit -m "Jenkins File created"

devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git commit -m "Jenkins file created "

[master 9e50b6e] Jenkins file created

3 files changed, 32 insertions(+)

create mode 100644 Jenkinsfile

create mode 100644 website

create mode 100644 website.txt

Run the command skunk commit -m “Jenkins File created” The message at the top of the commit ought to be one thing associated with what the commit contains — perhaps it’s

a new feature, perhaps it’s a bug fix, perhaps it’s simply fixing a mistake. Don’t place a message like “asdfadsf” or “foobar”.

Step 5: Create a new branch

Now that you’ve created a brand new commit, let’s strive one thing a touch additional advanced.

Say you wish to create a brand new feature however square measure disquieted concerning creating changes to the most project whereas developing the feature.

Branches allow you to move back and forth between the ‘states’ of a project.

For instance, if you wish to feature a brand new page to your web site you’ll be able to produce a brand new branch only for that page while not touching the most a part of the project.

Once you’re finished the page, you’ll be able to merge your changes from your branch into the master branch. After running the above command, you can use the git branch the command to confirm that your branch was created:

devops-ndi-lap-688:~/Desktop/Projects/maven-project$ git Branch

master

* Development

The branch name with the asterisk next to it indicates which branch you’re pointed to at that given time.

Now, if you switch back to the master branch and make some more commits, This command can mechanically produce a brand new branch so mechanically you out’ on that, which means GIT can move you merge a branch, off of the master branch.

Step 6: Create a new repository on GitHub

If you merely wish to stay track of your code regionally, you oughtn’t to use GitHub.

But if you wish to figure with a team, you’ll be able to use GitHub to collaboratively modify the project’s code.

To create a brand new repo on GitHub, log in and move to the GitHub home page.

You should see an inexperienced ‘ New repository’ button: when clicking the button, GitHub can raise you to call your repo and supply a quick description:

Step 6 New repository is created (maven-project)

Step 7 Let’s push the Git code to the repository (Maven -Project)

Step 8 we can see that code has been successfully pushed to Github Repository