Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating merge commit #24

Open
piyushchauhan2011 opened this issue Nov 14, 2021 · 7 comments
Open

Avoid creating merge commit #24

piyushchauhan2011 opened this issue Nov 14, 2021 · 7 comments

Comments

@piyushchauhan2011
Copy link

piyushchauhan2011 commented Nov 14, 2021

I want to know if it's possible if we can avoid creating merge commit and do a fast forward with some option. Right now it creates two commits

Screen Shot 2564-11-14 at 16 35 47

e.g. https://github.com/piyushchauhan2011/bug-free-palm-tree/commits/staging

@andrewfenn
Copy link
Contributor

Yes I would like to know this too. For example when there is no changes to be applied it will create an empty commit that does nothing.

@andrewfenn
Copy link
Contributor

I have made a pull request that skips merges for fast-forwards
#28

@peterlauri
Copy link

It would be handy to have a configuration like:

allow_fastforward: true

@isaachinman
Copy link

Is there any update on this issue's original request? In our org we prefer squash merging, and only want to have a single commit on the master/main branch.

If anyone is aware of how to make this possible with devmasx/merge-branch, or indeed a raw bash/octokit script, please let me know.

@piyushchauhan2011
Copy link
Author

piyushchauhan2011 commented Feb 28, 2023

@isaachinman

For now I switched to bash script. My use case was to auto sync main branch to staging for deployment purposes

name: staging flow

on:
  workflow_dispatch: # trigger job manually
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Release to staging
        run: |
          git config user.email "[email protected]"
          git config user.name "Organization CI"
          git checkout -b staging # staging branch for deployment
          git reset --hard main # auto replace staging with main branch for deployment 
          git push -f --set-upstream origin staging

If staging branch is protected, it will fail. So generally, best to create a bot github account and give force push rights and set appropriate email and name

@isaachinman
Copy link

@piyushchauhan2011 I believe there are many prebuilt GH actions for that exact purpose. For anyone looking to merge a PR/branch without a merge commit, this is what I ended up with:

name: Auto-Merge Pull Requests

on:
  pull_request:
    types: [labeled]

jobs:
  auto_merge_prs:
    name: Auto-Merge PRs
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
        with:
          fetch-depth: 0

      - name: Merge changes into master
        run: |
          git config --local user.email "[email protected]"
          git config --local user.name "Github Actions"

          git switch master
          git merge origin/my-branch --no-commit

          git push origin master

Quite simple in the end. Will see how it holds up over time.

In terms of branch protection, scope PATs are probably a cleaner solution than bot accounts.

@piyushchauhan2011
Copy link
Author

Nice 👍🏼 . I agree with PATs, easier to maintain than bot accounts if they are only used for just this purpose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants