Can I edit two files then make one commit using GitHub Web-based editor?

GitGithubGit Commit

Git Problem Overview


GitHub has the nice feature of Web-based file editing. However, it seems that after editing one file I have to commit the changes for this file before continuing. Is there a way I can edit two or more files then make one commit for all the changes of them?

I think this would be better since too many unnecessary commits are annoying.

Git Solutions


Solution 1 - Git

There is a web-based workaround:

  1. Create a temporary branch, switch to it;
  2. Edit multiple files, commit each file separately;
  3. Make pull request;
  4. Under Merge pull request button, choose Squash and merge (if the repo allows it), then confirm merge;
  5. Delete temporary branch.

I use this method on a PC which I don't want to install git on.

Solution 2 - Git

Yes there is a way to edit 2 files, when you've already edited your first file in the web browser view of GitHub. It's based on the instructions here:

https://webapps.stackexchange.com/questions/95940/how-can-i-change-multiple-files-and-submit-them-in-one-pull-request-on-github

The summary and clarified steps are:

  1. Edit your first file, by clicking the Edit icon in another user's repository. Save this edit in your first commit. GitHub will automatically create a new branch/fork for you, like "patch-1".
  2. Do not create a Pull Request yet.
  3. [This part is the most difficult, because it's not obvious] Go to the list of repositories in your profile, at github.com ➔ click icon at top-right ➔ Your Repositories. Then go to the forked repository that you've just made, and switch to the "patch-1" branch.
  4. Continue making changes to another file, and commit it to your "patch-1" branch. When you are done, click the "Pull Requests" tab near the top, then click Compare & Pull Request or Create Pull Request. You should see your 2 commits in this Pull Request.
  5. If you don't see a "Create Pull Request" button, open a URL like this in your web browser: https://github.com/TargetPerson/TargetGitRepo/compare/master...MyGithubUsername:patch-1
  6. This will show a view to compare your changes to the original target branch in the other user's repository. Then press the Create Pull Request button.

Solution 3 - Git

The GitHub Web Flow supports one file per commit. To add multiple files to a single commit, you will need to clone the repository locally, edit the files, then commit and push.

The command line would be like this:

  1. cd to the directory

  2. Stage all modified files with

     git add <file-1> <file-2> <etc>
    
  3. Commit with

     git commit -m'<your-message>
    

    or if you want to launch an external editor

     git commit
    
  4. Send the history/commit with

     git push
    

Solution 4 - Git

Addendum to what @VictorIstomin and @MarCnu were saying:

If you want to edit a number of filenames instead of the contents of those files, simply follow the instructions that Victor laid out, but you won't have to "Confirm Squash and Merge". You can just hit "Confirm Merge" (which should be the only option, since you didn't actually edit file contents.

The question has been answered well, just wanted to clarify this for any future viewers who might be changing filenames, which is something I commonly do in GitHub.

Solution 5 - Git

Let's assume the repo in question is https://github.com/repoUsername/repoName

  1. Fork the repository by clicking the Fork button at the top of the repo page.

enter image description here

  1. Edit as many files as you want via Web-based file editor in your fork of the repo. Commit each file individually.

  2. Go to https://github.com/repoUsername/repoName/pulls and press the big green New pull request button.

enter image description here

  1. On the next page click compare across forks link.

enter image description here

  1. Then in Choose a Head Repository field select your fork

enter image description here

  1. Create pull request button will appear. Click it.

enter image description here

  1. Enter title and description of your pull request and click Create pull request button again.

enter image description here

Solution 6 - Git

If you don't wish to create a temporary branch and merge the changes (which results in a bunch of pull requests in the repository that were just used to merge commits), you can upload multiple (modified) files and GitHub will create a single commit with them.

Note that, when uploading files, the files will be uploaded to the current folder visible on GitHub.

The disadvantage of this method is that, when you need to modify files that are in different directories, you will need to either upload all your project files (which will be slow) or create a skeleton directory of your project and place the modified files there (so that GitHub modifies the correct files and does not create a new file).

Be careful when using this method because GitHub will not show you your changes until after you have committed the files.

Solution 7 - Git

The new and better approach is to use the GitHub integrated online VSCode editor.

  1. Press . (period) on your keyboard when viewing your repository. This launches an in-browser VSCode instance (on github.dev).
  2. Make your changes across multiple files, just as you would do locally.
  3. Use the sidebar on the left to select the Git menu, and commit/push through the GUI as normal. You can also create a Pull Request there if you don't have write permissions.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionshengbinmengView Question on Stackoverflow
Solution 1 - GitVictor IstominView Answer on Stackoverflow
Solution 2 - GitMr-IDEView Answer on Stackoverflow
Solution 3 - GitJordan McCulloughView Answer on Stackoverflow
Solution 4 - GitdavidqshullView Answer on Stackoverflow
Solution 5 - GitIlyichView Answer on Stackoverflow
Solution 6 - GitsomethingRandomView Answer on Stackoverflow
Solution 7 - GitFoxInFlameView Answer on Stackoverflow