Can I edit two files then make one commit using GitHub Web-based editor?
GitGithubGit CommitGit 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:
- Create a temporary branch, switch to it;
- Edit multiple files, commit each file separately;
- Make pull request;
- Under Merge pull request button, choose Squash and merge (if the repo allows it), then confirm merge;
- 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:
The summary and clarified steps are:
- 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".
- Do not create a Pull Request yet.
- [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. - 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.
- 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
- 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:
-
cd
to the directory -
Stage all modified files with
git add <file-1> <file-2> <etc>
-
Commit with
git commit -m'<your-message>
or if you want to launch an external editor
git commit
-
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
- Fork the repository by clicking the
Fork
button at the top of the repo page.
-
Edit as many files as you want via Web-based file editor in your fork of the repo. Commit each file individually.
-
Go to https://github.com/repoUsername/repoName/pulls and press the big green
New pull request
button.
- On the next page click
compare across forks
link.
- Then in
Choose a Head Repository
field select your fork
Create pull request
button will appear. Click it.
- Enter title and description of your pull request and click
Create pull request
button again.
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.
- Press . (period) on your keyboard when viewing your repository. This launches an in-browser VSCode instance (on github.dev).
- Make your changes across multiple files, just as you would do locally.
- 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.