Wednesday, August 25, 2021

Fatal: Not possible to fast-forward, aborting


Ever tried to push your file changes to a git repository and get the failed to push some refs error?


Did you pull from the branch already to get the latest changes?

As in: Did something change on the remote or did you rewrite git history locally?

You might think, "Since I'm the only one making changes to the branch, why would I need to do a git pull?"

Maybe you’ve accepted some suggestions from code review? Those count as commits as well.

Or you clicked the button that pulls in master.

If so, your branch is no longer directly based off of the branch you're trying to merge it into.

You can rebase your branch on top of the destination branch (git rebase ) to rework the commits such that they will fast forward into it, or you can do a regular merge.

git push


Here's an example of a time when I tried to push my local index to a github repository:




When I say "git index" I'm talking about the files I changed, added and committed to my local git repository.

The changed files are in git's local staging area, also known as "the git index".

Same Error

I followed the instructions and did a git pull and then a git push again.

Same error.



The fix


Did you change your history locally?

As in: If you did a rebase or git commit --amend or similar locally your repo can get into a state like that. In this case, you need to force push.

Ends up I modified a file on github.com and when I saved it, it got "auto-merged"




git pull origin show-recent-tagged-pkg-versions --rebase might do the trick





This work is licensed under the Creative Commons Attribution 3.0 Unported License.

Tuesday, June 22, 2021

Create a Text File in Go

Here's a simple way to create a text file and write a line to it in Golang:

Example


	tempDir := t.TempDir()
	p := filepath.Join(tempDir, "Dockerfile")
	f, err := os.Create(p)
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	f.WriteString("FROM alpine:latest")
    


In this case, we created a Dockerfile in a temporary directory.

Notice how in Go we immediately handle error conditions and defer the closing of the file, which is handled automatically by Go.


This work is licensed under the Creative Commons Attribution 3.0 Unported License.