How to Commit and Push Changes from Ubuntu 18.04 to GitHub

Reading Time: 2 minutes

In our previous tutorial, we showed you how to create and sync a GitHub repository to your Ubuntu VPS server.  Using the last tutorial as a springboard, we’ll continue on and show you how to commit and push a script from your Ubuntu server to your GitHub account.

Step 1: Create a File

After we SSH into our server, open a terminal and cd into the folder we created in the previous article. In this folder, we will create a simple JavaScript program.

vim helloworld.java
public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}
helloworld

Step 2:  Checking our New Script’s Status

Next, using the following command, you’ll see that the helloworld.java file is highlighted in red indicating that the data has not yet been committed to our GitHub account.

git status

Example Output:

java.highlighted

Step 3: Adding an Index to Github

Adding an index for your script can be done by using the git add command. Once you perform the command, you’ll see your script name is now highlighted in green, letting you know it’s been appropriately indexed.

git add helloworld.java

Example Output:

git.add

Step 4: Committing the Script

Commit the script by utilizing the commit command followed by the -m flag. Place the command of your choice in quotes along with the file, helloworld.java. Committing your script pushing the script to your local repo.

git commit -m "First java program" helloworld.java

Example Output:

git.commit

Step 5: Pushing Script to Github Account

Committing the script means that the changes to your file have been recorded, but it doesn’t mean that they were pushed to your remote repository, aka your Github account, to do that use the push command. Afterward, you’ll be prompted to put in your username and password to your Github account.

git push -u origin master

Example Output:

root@merovingian2:~/git_environment/test# git push -u origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 465 bytes | 232.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/drsinger1/test.git
   cd5837c..a19b483  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
root@merovingian2:~/git_environment/test#  

Step 6: Verifying the Push

We can verify that this script was pushed to our repo by going to our Github account and refreshing the screen for your particular repo.  In our pictured example, my helloworld.java is now present.

first.commit

Conclusion

GitHub has many exceptional uses. Not only is it used for code storage and versioning, but it can also be utilized for storing blog info, images, lists of any kind, handbooks, ongoing documentation, datasets, or even recipes! All in all, GitHub is an excellent tool to have in your skill set.

We pride ourselves on being The Most Helpful Humans In Hosting™!

Our Support Team is full of experienced Linux technicians and talented System administrators who have intimate knowledge of multiple web hosting technologies, especially those discussed in this article.

Should you have any questions regarding this information, we are always available to answer any inquiries with issues related to this article, 24 hours a day, 7 days a week 365 days a year.

If you are a Fully Managed VPS server, Cloud Dedicated, VMWare Private Cloud, Private Parent server, Managed Cloud Servers, or a Dedicated server owner and you are uncomfortable with performing any of the steps outlined, we can be reached via phone @800.580.4985, a chat or support ticket to assisting you with this process.

Author Bio

About the Author: David Singer

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Refer a friend and get a $50 hosting credit!