Use git to make small changes but follow master easily

Hey, I have mostly used git superficially (git add, commit, push), but I’d like to use it to make a few smaller changes to a repository, and as simply as possible follow the master branch while keeping those changes.

I’m sure this is a common usecase, do you think you could point me in the right direction for that workflow?

Working directly on the main branch is usually not recommended. But making a series of small commits is usually considered a best practice.

‘atomic commits’ and ‘feature branch’ are the phrases to research.

I think I’m using the wrong language actually, I want to fork someone elses repo, then maintain some small changes, but easily pull in their updates.

I think with the adjustment of language I might have got what I’m looking for out of chatgpt:

  • Fork the repository: The first step is to fork the repository on GitHub by clicking on the “Fork” button on the top right corner of the repository page. This will create a copy of the repository in your GitHub account.
  • Clone the forked repository: Clone the forked repository to your local machine using the git clone command. For example, if your forked repository is called “my-forked-repo”, you can run the following command:

bash

git clone https://github.com//my-forked-repo.git


* Create a new branch: Once you have cloned the repository, create a new branch using the `git branch` command. For example, you can create a new branch called "my-changes" by running the following command:

perl

* ```
git branch my-changes
  • Switch to the new branch: Switch to the new branch using the git checkout command. For example, you can switch to the “my-changes” branch by running the following command:

perl

git checkout my-changes


* Make your changes: Make your changes to the files in the repository using your favorite text editor or IDE.
* Stage your changes: Once you have made your changes, stage them using the `git add` command. For example, if you have made changes to a file called "index.html", you can stage those changes by running the following command:

csharp

* ```
git add index.html
  • Commit your changes: Commit your changes using the git commit command. For example, you can commit your changes with the following command:

sql

git commit -m “My changes”


* Push your changes: Finally, push your changes to your forked repository using the `git push` command. For example, you can push your changes to the "my-changes" branch by running the following command:

perl

* ```
git push origin my-changes

This will push your changes to your forked repository on GitHub.

  • Pull changes from the upstream repository: To pull changes from the upstream repository (the original repository you forked), you need to add it as a remote repository using the git remote command. For example, you can add the upstream repository as a remote repository by running the following command:

csharp

git remote add upstream https://github.com//.git


This command adds the upstream repository as a remote repository named "upstream".
* Fetch changes from the upstream repository: Fetch the changes from the upstream repository using the `git fetch` command. For example, you can fetch changes from the upstream repository by running the following command:

sql

* ```
git fetch upstream

This command fetches the changes from the upstream repository but does not merge them with your local repository.

  • Merge changes from the upstream repository: To merge the changes from the upstream repository into your local repository, switch to your local master branch and use the git merge command to merge the changes. For example, you can merge changes from the upstream repository by running the following commands:

bash

git checkout master
git merge upstream/master


This will merge the changes from the upstream repository into your local master branch.
* Merge changes from the master branch to your own branch: Finally, switch to your own branch and merge the changes from the master branch using the `git merge` command. For example, you can merge changes from the master branch

Forking somebody else’s repo and making changes while maintaining compatibility with their changes is hard, messy, and not recommended.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.