Git Logo

Git Fundamentals in Ubuntu

In this post we will cover basic git commands used to Initialize a new repository (Git Init), check the status of our new repository (Git Status)

add files to the staging area (Git Add) commit staged files to the repository (Git Commit)

In our Linux terminal once we have navigated to or created the folder that we want to use as our new repository we can use the git init command to initialize the repository. Once the repository has been initialized, we can use git status to verify that the repository was successfully created and is ready to accept new solution artifacts. Once the repository has been initialized the git status command should verify that we are on the master branch and that the working tree is clean. We can then use our preferred text editor to create a new file that will represents a solution artifact.

Note: In the linked YouTube video, we use the Vi editor but you can use whatever editor you prefer.

For the purpose of this discussion, we can simply create a file called readme.txt. Since you can’t have a programming discussion without at least one Hello World let’s get it out of the way add the text “hello world” to the file and save and close it.

Now that we have a new file in our repository, we can again run the git status command to check the status of our working tree.

At this point git status should notify us that we have untracked files in our repository and we can use the get add command to track these files. So, let’s go ahead and do that. We can use the “git add .” command to add all of the files in the current directory to the repository. You can also add specific files by listing the files to add in a comma separated list.

Once we have successfully added our new file to the staging area, we can run git status to verify that our files are now being tracked and waiting to be committed to the repository.

To commit our newly staged files the repository we can use the git commit command with the -m switch to add the required commit message. If we do not use the -m switch we will be prompted for the commit message as soon as we hit enter.

After successfully committing the new file to the repository executing git status again will indicate that now our working tree is clean and there are no changes to commit.

These are the basic commands discussed in the YouTube video linked below. Check out the video on YouTube for additional details and examples of these basic git functions in action. Click the link below.

How To: Initialize a Git Repository and add then commit project artifacts

1 thought on “Git Fundamentals in Ubuntu”

  1. Pingback: How to Stage, UnStage and Commit a Java Maven Project to a Git Repo in Eclipse on Ubuntu – @ProDataMan

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Shopping Cart