git rebase master

and you get conflicts. Here’s how to proceed:

1. fix conflicts

Look for CONFLICT and edit the file mentioned. Note: the path is to the root of the git repo not where you are currently

2. git add <conflicted files>

3. git rebase –continue

Once you’ve merged and do a git status I got:

This would be because I’d already pushed my feature branch. i.e. you’re changing the history of all those commits by doing the rebase

The solution is, assuming you’re the only one using your feature branch, is to force push.

A trick to make this less dangerous is to use git push --force-with-lease rather than git push -f. This way if someone did get hold of your feature branch and push a change it would fail instead of overwriting the new commit.

However the golden rule is – don’t use rebase on public branches. If you’ve pushed then

 

More here:

https://stackoverflow.com/questions/19016698/git-branch-diverged-after-rebase

and here: https://stackoverflow.com/questions/34678950/git-branch-has-diverged-after-rebase-so-why-rebase/34679616

and https://www.reddit.com/r/git/comments/6jzogp/why_am_i_force_pushing_after_a_rebase/

 

Note: If everything goes wrong:

git rebase –abort

How do you copy a directory?

This is one of the most basic tasks you can do.

But it’s fraught with complexity.

The obvious requirement here is I want to copy a directory exactly as it is from A to B.

So, let’s try this on the Mac (note: this will be different if you’re on Linux):

cp -r 

I had symlinks so I got:

cp: some/directory/structure: No such file or directory

Let’s check man cp.

so cp -r does not copy symlinks.

Note: I use tldr which incorrectly says:

-a

Why? ‘cos if we look at -Pwe see:

So that’s not going to work.

OK, moving on. Let’s look at -R. Seems more like it.

On a large directory this took forever though. As an alternative, let’s try:

rsync -pvzar

Hmm. Measuring the time this took on a large directory (14 G), rsync was 50% slower.

 

More notes:

Should you have a trailing slash? On the source directory? The destination directory? Both? None?

You need the trailing slash on the source directory but the destination is optional. i.e. both of these work:

cp -R source/ destination/

cp -R source/ destination

but this:

cp -R source destination

would copy source into the destination directory.

and

cp -R source/* destination

would not copy dot files to destination.

 

A trailing / at the end of a pathname forces the pathname to refer to a directory.

https://unix.stackexchange.com/questions/1910/how-does-linux-handle-multiple-consecutive-path-separators-home-username

https://serverfault.com/questions/11518/recursive-cp-copies-folder-contents-instead-of-folder-on-os-x

https://www.linuxquestions.org/questions/linux-newbie-8/trailing-slash-or-not-4175535239/

https://superuser.com/questions/1016843/how-do-you-copy-directories-in-linux-in-these-situations-using-cp

https://superuser.com/questions/1016843/how-do-you-copy-directories-in-linux-in-these-situations-using-cp

 

tmux

Install

then

Split terminal:

  • horizontally: Ctrl b "
  • vertically: Ctrl b %

Move between panes:

  • Ctrl b <arrow key>

(although this interfered with a Mac keyboard shortcut)

More: https://hackernoon.com/a-gentle-introduction-to-tmux-8d784c404340

 

Ansible: Proxy using ProxyCommand

https://stackoverflow.com/questions/28553307/ansible-using-custom-ssh-config-file

and https://stackoverflow.com/questions/38651791/is-it-possible-to-add-ansible-ssh-common-args-in-inventory-file

https://www.cyberciti.biz/faq/linux-unix-ssh-proxycommand-passing-through-one-host-gateway-server/

curl: PUT

Testing curl PUT commands.

Start by creating an HTTP PUT server:

and run with python SimpleHTTPPutServer.py

then:

curl -XPUT -H "Content-Type: application/json" http://localhost:8000 -d '{"test": null}'

and now you can mess around creating arbitrary PUT commands.

E.g.

  1. spaces don’t matter between -H and quotes.

-H"Content-Type

is the same as:

-H "Content-Type

2. Double quotes == Single quotes. E.g.

-H'Content is OK

3. argument to -dmust be surrounded in quotes. E.g.

-d 'test=test' is OK.

-d test=test is NOT OK.

E.g. see examples here:

https://gist.github.com/subfuzion/08c5d85437d5d4f00e58

 

Will restarting sshd disconnect you?

Say you’re on a bastion host and want to restart sshd with:

 

Is it going to disconnect you?

No.

What you will see if you’re tailing /var/log/auth.log is:

https://serverfault.com/questions/141205/restart-ssh-on-a-machine-where-ssh-is-the-only-mode-of-access

 

AWS: reliable? It ain’t!

Let me caveat that.

There’s some idea that stuff is bulletproof once on AWS. It’s not.

AWS has internal issues as do any provider. E.g. network problems (remember that S3 EOF bug?), disk drives failing (Retirement Notifications anyone?), etc

On top of that, stuff will hit internal inconsistencies. E.g. you have an ASG which tries to launch an EC2 instance only to fail ‘cos you’ve reached your limit for that particular type of EC2 instance.

But you can build around it in your app with Error Retries and Exponential Backoffs (techniques probably more familiar to mobile developers):

https://docs.aws.amazon.com/general/latest/gr/api-retries.html

 

E.g. here’s a solution Terragrunt uses: https://github.com/gruntwork-io/terragrunt/blob/master/README.md#auto-retry