DevOps Elastic Hayway
Document

SUBSCRIBE TO GET FULL ACCESS TO THE E-BOOKS FOR FREE 🎁SUBSCRIBE NOW

Professional Dropdown with Icon

SUBSCRIBE NOW TO GET FREE ACCESS TO EBOOKS

GitLesson 6 / 206 min readUpdated September 11, 2026

Git Workflow Commands

  Below is the example for git workflow and it shows the different stages with git commands to manage local and global repositories (I am using Git Lab but you can use Github also)

Local Repo:– git 

Remote Repo:– Git Hub ( https://github.com)

Consider You are a developer and working on a java project and the name of the project is SpringBootMicroservice. In this project, there are a couple of files ( I am creating some dummy files with extension .java). This project is running on a development box so You need to set up local configuration file ( with your name as Author and your email as email)

Step 1:- Create folder SpringBootMicroservice which has my project files.

mkdir SpringBootMicroservice

Step 2: – Create required files ( restapi.java,dao.java,services.java)

cd SpringBootMicroservices
touch restapi.java dao.java services.java

Step 3: – Initialize this project with git init command

git init

Step 4: – Check that there must be a .git directory get created which is responsible for managing this project’s repo.

ls -la
ls .git

Step 5: – Setup the Author name and Author’s Email address for this project locally.

git config --local user.name raman
git config --local user.email raman@gmail.com

Step 6:– Verify in .git/config file that the author name and email address is properly configured

cat .git/config

Step 7: – Check the local repository status.(all 3 files should be untracked)

git status

Step 8:– Push dao.java file to the stage area

git add dao.java
git status

Step 9:– Unstaged (moving stage to untracked) dao.java file

git rm --cached dao.java
git status

Step 10:– Push all the files in the stage area.

          git add .   # or you can use git add -a

git status

Step 11:– Commit dao.java file in the local repo.

           git commit -m “dao.java is added” dao.java

git log

Step 12: – Commit all the files in the local repo.

          git commit -m ” restapi and services java files are added”

git status
git log
git log --oneline


Github Repository


Step 1: Create new Repository in Github.

            Goto Github.com and log in with your credentials.

Step 2: Click on New button or click on Start project button

Step 3: Provide following information for the Git Repo

           Repository name: SpringBootMicrroservice

           Select Public radio button

         Click on Create Repository

Step 4: Create token in Github

           Select Settings from the account.

           Select Developer Settings

           Click on Personal Access token

           Click on Generate new Token

           Provide following information

                 Note: token1

                 Expiration: 7 days

                 tick mark :- repo, admin.org 

           click on Generate token

           and note down the token number

Step 4: Click on HTTPS and copy the HTTPS URL

Step 5: Run below set of commands to push the code from local repo to Github Repo

git branch -M main
git remote add origin <<HTTPS URL>>
git push origin main

           provide user name as Github username and password as token value

Step 6: Verify the main branch gets created on the Github and all the files of the local repo are available on the Github repo.


Connect local git repo with Github using SSH keys

Step 1: Create ssh keys on the local system

            ssh-keygen

            copy the content of /root/.ssh/id_rsa.pub file

Step 2: Goto Github Repo –>Settings –> Deploykeys

          Click on Add key button and paste the content of the ssh key

          Click on Allow write Access check box.

          Click on Add key button

Step 3: Copy the ssh URL of your Github repo.

Step 4: vi .git/config

     in [remote origin]

   replace URL with the ssh URL of your Github repo.

Step 5: Create a new file in your local repo and push it to the Github Repo.

touch bal.java
git add bal.java

       git commit -m “bal.java file is added”

Step 6: Push the local Repo to Github repo

git push origin main

Share your love

Leave a Reply

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