Skip to content

Instantly share code, notes, and snippets.

@x-yuri
x-yuri / bash: backticks and a backslash.md
Last active December 28, 2024 12:08
bash: backticks and a backslash

bash: backticks and a backslash

Before executing a command in backticks certain preprocessing takes place:

  • \\ becomes \ (`echo \\\\` -> echo \\ -> \)
  • but if there's a \ not followed by \, then \ remains \ (`echo \\\ ` -> echo \\ -> \)
  • unquoted \ at the end of the resulting command remains \ (`echo \\` -> echo \ -> \), but this is not exactly about backticks (bash -c 'echo \' -> \)
  • \" remains \" (`echo \"` -> echo \" -> ")
  • but in double quotes \" becomes " ("`echo \\\"`" -> echo \" -> ")
  • \$ becomes $ (`a=1; echo \$a` -> a=1; echo $a -> 1)
@x-yuri
x-yuri / git push.md
Last active December 22, 2024 07:13

[git push][d]

$ git push [<repository> [<refspec>...]]

Updates remote references along with their history.

<refspec> tells git which remote reference to update with which local one.

@x-yuri
x-yuri / git pull.md
Last active December 22, 2024 07:12
git pull

[git pull][b]

$ git pull [<repository> [<refspec>...]]

Basically does [git fetch [<repository> [<refspec>...]]][a] + git merge FETCH_HEAD (git rebase FETCH_HEAD).

If multiple <refspec>'s are passed or a <refspec> resolves to multiple references, then all the resolved references are merged into the current branch (rebase is possible only when one reference is to be rebased onto). If there's only one reference, it's merged into the current branch (the current branch is rebased onto it).

@x-yuri
x-yuri / git fetch.md
Last active December 22, 2024 07:12
git fetch

[git fetch][a]

$ git fetch [<repository> [<refspec>...]]

Fetches references along with their history into the local repository.

<refspec> tells git which local reference to update with which remote one.

@x-yuri
x-yuri / git: FETCH_HEAD.md
Last active December 24, 2024 14:03
git: FETCH_HEAD

git: FETCH_HEAD

the Stack Overflow answer

git fetch writes the references it fetches to .git/FETCH_HEAD (one per line). If the upstream branch is set, the corresponding reference is marked for merging. FETCH_HEAD is the reference (i.e. the remote-tracking branch) marked for merging if the upstream branch is set, or the first reference in .git/FETCH_HEAD otherwise.

Basically after git fetch (or git pull) FETCH_HEAD points to the tip of the upstream branch, that you want to merge or rebase onto.

The relevant docs:

@x-yuri
x-yuri / git: push.default.md
Last active December 22, 2024 07:13
git: push.default

git: [push.default][a]

The setting determines which local branches git push and git push <repository> should push and where. (It also affects some other cases, see [git push][c].) To put it briefly:

  • nothing - push nothing (error out)
  • upstream - push the current branch to the [upstream branch][b]
  • simple (the default) - push the current branch to the matching (the same name) [upstream branch][b] (upstream + branch names should match)
  • current - push the current branch to the matching branch in the chosen remote
  • matching - for each local branch l, if there's a branch r in the chosen remote that has the same name, then push l to r
@x-yuri
x-yuri / git: push.default = matching.md
Last active December 14, 2024 21:07
git: push.default = matching

git: push.default = matching

Obsoleted by https://gist.github.com/x-yuri/a25ae25574e4b7e3b0f37cbed04e2035.

In this mode git push pushes matching branches, i.e. all local branches that exist in a remote, to their remote counterparts (if there's a local branch ba and a remote branch origin/ba, it pushes ba to origin/ba):

  • First it chooses a remote:
    • if the current branch has an upstream, it chooses the remote the upstream points to
    • else if there's only one remote, it chooses this only remote
    • else it chooses origin if it exists
@x-yuri
x-yuri / git: upstream branches.md
Last active December 22, 2024 07:11
git: upstream branches

git: upstream branches

[branch.<name>.remote][a] and [branch.<name>.merge][b] together define the upstream branch for the given branch (if they're set, the given branch has an upstream branch). . as a remote denotes the local repository.

E.g. if branch.dev.remote = origin and branch.dev.merge = refs/heads/dev, then origin/dev (the remote-tracking branch of the remote branch dev) is an upstream of dev.

Or if branch.a.remote = . and branch.a.merge = refs/heads/b, then b is an upstream of a.

The upstream branch tells (under certain circumstances):

@x-yuri
x-yuri / git checkout: -t, --track, --no-track.md
Last active December 13, 2024 13:31
git checkout: -t, --track, --no-track

git checkout: -t, --track, --no-track

These options override the branch.autoSetupMerge setting:

  • -t, --track, --track=direct make the starting point the upstream of the branch that's being created
  • --track=inherit copy the upstream configuration (if such exists) from the starting point to the branch that's being created

a.bats:

@x-yuri
x-yuri / git checkout -b.md
Last active December 27, 2024 00:09
git checkout -b

git checkout -b

Generally, to create a branch and switch to it, here's the command:

$ git checkout -b <branch> [<start-point>]

If you want to create <branch> and made <remote>/<branch> its starting point and upstream though, you can omit the -b <branch> part: