top of page

Tutorial blog to understand additional Git facilities in Cloud9 (Part 2)

Updated: Oct 18

Learning Objective:

  • To learn additional Git commands on Cloud9.


  • Git intro part 1. Refer this blog.

Step 1: In AWS Management Console, go to Cloud9 and create an environment as shown in part 1. Open that environment.

Step 2: Click on the source control icon then click on Initiate Repository. Select your environment from the list and a Git repository is created.

Step 3: Go to File menu and select New from Template and Python.

Paste the following code in the Python file:

# Function to add two numbers def add(x, y): return x + y # Function to subtract two numbers def subtract(x, y): return x - y # Main program loop while True: # Display menu print("Options:") print("Enter 'add' for addition") print("Enter 'subtract' for subtraction") print("Enter 'quit' to end the program") # User input user_input = input(": ") # Check if user wants to quit if user_input == "quit": break # Check for valid operation if user_input in ("add", "subtract"): num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) if user_input == "add": print("Result:", add(num1, num2)) elif user_input == "subtract": print("Result:", subtract(num1, num2)) else: print("Invalid input")

Save this file as

Paste following 2 commands in the bash terminal. Replace 'your_GitHub_username' with your username and similarly replace 'your_email' with your e-mail ID.

git config --global your_GitHub_username

git config --global your_email

Add, and commit this code with the message created baseline.

Note: In the next steps we will show how to transfer code from one branch to another in 2 ways – Stashing and Branch Merging.

Step 4: Click on the branch name on the bottom left and select Create newbranch. Name this new branch calc.

Add the following code below the addition and subtraction functions in the code:

# Function to multiply two numbers

def multiply(x, y):

return x * y

# Function to divide two numbers

def divide(x, y):

if y == 0:

return "Cannot divide by zero"

return x / y

Save the file. Search for Stash in the search box in the top left and select Git: Stash. Press enter when asked for optional message in top left. Now switch branch to master and search for Pop Stash and select Git: Pop Stash.

Select the one entry for stashed code. Now you will see the code we had added in calc in cut and pasted to master branch.

Step 5: Delete the code we added in the last step from master branches and add and commit changes as second commit.

Now again add the code mentioned in the last step below add and subtract functions in the calc branch code and save the file. Add and comment it as added functions.

Change the branch to master and search for and select Git merge. Select the branch calc from the options to merge the 2 branches. If you get merge conflicts, removes staged changes in the master branch.

You will see that the code has been updated from calc to master branch.

Step 6(Optional): To pull changes made to remote repo, click on the push icon(cloud) on the bottom left of the screen. It should be in the form 2 circling arrows.

Note: Delete the environment after use.

Git_Intro_part 2
Download PDF • 387KB

Was this document helpful? How can we make this document better. Please provide your insights. You can download PDF version for reference.

We provide the best AWS training from Pune, India. For aws certification contact us now.

31 views3 comments

Recent Posts

See All
bottom of page