Logo

dev-resources.site

for different kinds of informations.

CLEAN GIT: Pushing Local Changes to Remote Repository Using Git

Published at
9/8/2023
Categories
tutorial
programming
git
webdev
Author
Rusydy
Categories
4 categories in total
tutorial
open
programming
open
git
open
webdev
open
CLEAN GIT: Pushing Local Changes to Remote Repository Using Git

In this Standard Operating Procedure (SOP), we will walk through the process of applying CLEAN GIT principles to efficiently push our local code changes to a remote repository. This SOP assumes a Git flow with branches such as staging, local/feature, UAT, and main. It also covers scenarios where code changes may require adjustments during the review process.

Git Flow Overview

Our Git workflow involves the following branches:

Git Flow

  1. local/feature: This branch is dedicated to feature development.
  2. main: The main branch serves as the central location for all integrated features.
  3. staging: QA tests features from the main branch.
  4. UAT: This branch is available for client testing.
  5. PROD: The production-ready branch.

It's important to note that while the main branch may contain untested features, the staging branch is reserved for QA-tested features.

Pushing Local Changes to Remote Repository

Let's delve into the steps of applying CLEAN GIT principles when pushing local code changes to the remote repository.

Step 1: Create a New Branch

Start by creating a new branch for your feature. In this example, we'll name it feature/TICKET-1234.



git checkout main
git pull
git checkout -b feature/TICKET-1234


Step 2: Develop the Feature

Develop your feature by adding or modifying files. In this instance, we create a new file called feature.txt and add content to it.



echo "This is a feature" > feature.txt


Step 3: Commit the Changes

Commit your changes to the local repository.



git add feature.txt
git commit


This will open your default text editor. You can use vim or another text editor to compose your commit message. For example:



[TICKET-1234]: Add feature.txt

Previously, we did not have a feature.txt file in the repository.

In this commit, we add the feature.txt file to the repository.

Thus, we can now use the feature.txt file.


Step 4: Fetch and Rebase the Latest Changes

Retrieve the latest changes from the remote repository and rebase your changes onto them.



git fetch --all --tags
git rebase -i --autosquash origin/main


This will open your default text editor. For example:



pick 1a2b3c4 [TICKET-1234]: Add feature.txt


Step 5: Push the Changes to the Remote Repository

Push your changes to the remote repository.



git push -u origin feature/TICKET-1234


Step 6: Create a Pull Request

Now, create a pull request to merge your changes into the main branch.

Handling Reviewer-Requested Changes

Major Changes with the Same Technical Decision

If the reviewer requests significant changes but the technical approach remains the same, you can amend your commit after making the necessary adjustments.



git add feature.txt
git commit --amend


Update the commit message to reflect the changes:



[TICKET-1234]: Add feature.txt

Previously, we did not have a feature.txt file in the repository.

In this commit, we add the feature.txt file to the repository.

Thus, we can now use the feature.txt file.




Major Changes with a Different Technical Decision

In case the reviewer requests substantial changes that involve a different technical approach, create a new commit to incorporate the new decision.



git add feature.txt
git commit




Minor Changes

For minor adjustments requested by the reviewer, you can amend the existing commit without changing the commit message:



git add feature.txt
git commit --amend --no-edit




Conclusion

In this SOP, we've outlined the CLEAN GIT principles for pushing local code changes to a remote repository. We've also covered how to handle reviewer-requested changes efficiently. In our next SOP, we'll explore how to apply CLEAN GIT principles to address hotfix requests in a production environment.

Featured ones: