How to push code from EC2 instance into a Github repository with Git bash

 

Pushing code changes from EC2 instance to GitHub using Git bash

Let us see how to push a code change using Git bash or iTerm from Jenkins EC2 instance into GitHub.

After configuring a freestyle job or pipeline using Jenkins for building and deployment, you would like to make a code change to make sure Jenkins have started automated builds/deployments.

Pre-requistes:
  • SSH keys set up and uploaded into GitHub.
  • Connect to Jenkins EC2 instance using GitHub.
  • Project setup already in GitHub
Steps:
1. Login to Jenkins EC2 instance first. Make sure you are inside EC2 instance.
2. Type below command to see if you have already cloned your repository.
ls -al

you should see the repo name. once you see the repo name, cd into repo folder

(If you don't see any GitHub Repo folder already cloned, you need to clone from GitHub by executing below command:

git clone git@github.com:user_name/your_repo.git

now go inside repo folder.

3. cd youreponame

change repo_name per your name of the repo you created in GitHub.

Go into below folder by typing the command:
4. Now try to get latest code changes from GitHub into local repo by performing below command:
git pull
5. cd MyWebApp/src/main/webapp
Now you can edit below file to reflect changes in Tomcat
6. sudo vi index.jsp

Change Hello world into below yellow highlighted:
<html>
<body>
<h2>Howdy Folks !!! Welcome to DevOps!</h2>
</body>
</html>

7. press escape, enter :wq!
8. git add index.jsp
9. git commit -m "made change to jsp"
10. git push

Now Login to GitHub and verify the code changes you made are pushed into your repo in GitHub.

Comments

Popular posts from this blog

Install Ansible on Ubuntu | How to setup Ansible on Ubuntu 22.0.4 | Ansible install on Ubuntu

Installing SonarQube using Docker || Installing SonarQube using Docker on Ubuntu 22.0.4 || Installing SonarQube using Docker-Compose

Setup build agent/slave VM and Integrate with Jenkins Master