Committing and Pushing to Github from Ubuntu 18.04

Reading Time: 2 minutesIn our previous tutorial, we showed you how to create and sync a Github repository to your Ubuntu VPS server 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

In our terminal, we’ll create a simple script. vim public class HelloWorld { public static void main(String[] args) { //Prints "Hello, Word" to the terminal window. Systems.out.printlin("Hello, World"0; } }

Step 2:  Checking our New Script’s Status

Using the following command, you’ll see that the file is highlighted in red indicating that the data has not yet been committed to our Github account. git status Example Output: root@1804:~/git_environment/want-some-java# git status On branch master Your branch is up to date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) nothing added to commit but untracked files present (use "git add" to track)

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 Example Output: root@1804:~/git_environment/want-some-java# git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file:

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, Committing your script pushing the script to your local repo. git commit -m “First java program” Example Output: [master 5519a7e] First java program 1 file changed, 6 insertions(+) create mode 100644

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: Counting objects: 3, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 447 bytes | 447.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To 588917c..5519a7e  master -> master Branch 'master' set up to track remote branch 'master' from 'origin'.

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 is now present.

Author Bio

About the Author: Echo Diaz

Throughout Echo's four year stint as a technical support specialist, her passion for breaking down complex concepts has to lead to a career in professional writing. As a top tier support specialist, she adds a distinctive element to her written work that speaks to customer feedback and concerns.

Echo occasionally pops her head out from behind her computer to watch her dog energetically run around the yard and unabashedly shovels money into buying tickets to see her favorite musical artists.

Refer a friend and get hosting credit!