[System] You are a helpful assistant.

[User]
Gitlab 8 with nginx proxy can't download a zip, clone a public repo as guest, can't build in CI either

I think all 3 problems are related to the same issue, so I'm going to put all of them here.
Gitlab itself is working, I even managed to update it from 8.2.2 to 8.2.3.
I can create projects, push my code, pull it, reclone it when I have the proper ssh key, etc.
BUT:

I can't download the code as zip file, got a JSON instead:

{"RepoPath":"/var/opt/gitlab/git-data/repositories/me/myrepo.git",
"ArchivePrefix": "...

People can't clone my public repo (empty repository error).

CI can't build my tests:

warning: You have cloned an empty repository. Checking out 12345 as
develop... fatal: reference is not a tree :
123456789mycommithash987654321
ERROR: Build failed with: exit status 1

NB: I Translated error messages from French ones.
I suppose the problem is in my Nginx configuration, but there is so much documentation I'm not sure which one is the good one: the ones with the workhorse, the ones when I have to change gitlab.rb's gitlab_git_http_server, etc.
My configuration is following:

Gitlab 8.2.3
Ubuntu Trusty (14.04)
Nginx 1.8

My gitlab is hosted on a subdomain using SLL so I added a Nginx proxy
/etc/gitlab/gitlab.rb:
external_url 'https://gitlab.mydomain.com'
nginx['listen_addresses'] = ['127.0.0.1', "[::1]"]
nginx['listen_port'] = 8080
nginx['listen_https'] = false

/etc/nginx/site_enabled/gitlab:
server {
  listen *:80 default_server;
  listen [::]:80 ipv6only=on default_server;
  server_name gitlab.mydomain.com;
  return 301 https://$server_name$request_uri;

  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;
}

server{
  # listen 443 ssl;
  listen 0.0.0.0:443 ssl default_server;
  listen [::]:443 ipv6only=on ssl default_server;
  server_name gitlab.mydomain.com;
  server_tokens off;

  location /{
    proxy_pass http://localhost:8080;
    proxy_redirect off;
    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
  }

  location ~ ^/(assets)/ {
    root /opt/gitlab/embedded/service/gitlab-rails/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  client_max_body_size 250m;

  # ...
  # A lot a of SSL stuff (HSTS, OCSP, dhparam, etc)
  # ...

  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  error_page 502 /502.html;

UPDATE :
Just upgraded Gilab to 8.3.0.
Git a 502 now.
Applying : https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/update/8.2-to-8.3.md.
We'll see.
UPDATE 2:
Did not finish instructions after all, stop everything and restarting everything twice (Gitlab and Nginx) Finally managed to get the thing working.
Still same problems with CI/Zip/PublicCloning tough.
UPDATE 3:
Just update to 8.2.3
apt-get update
apt-get install gitlab-ce
502.
restart nginx
gitlab-ctl restart
gitlab-rake gitlab:app:check
Checking GitLab ...

Git configured with autocrlf=input? ... yes
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory setup correctly? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
projects have namespace: ...

Redis version >= 2.8.0? ... yes
Ruby version >= 2.1.0 ? ... yes (2.1.7)
Your git bin path is "/opt/gitlab/embedded/bin/git"
Git version >= 1.7.10 ? ... yes (2.6.1)
Active users: 2

Checking GitLab ... Finished

If someone can lead me to the proper documentation or changes to be made that would be awesome.

[Assistant]
It looks as though downloading of ZIP-Files is now handled by the gitlab-workhorse.
For that there's some extra stuff in the nginx-configfile. You might want to have a look at https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/support/nginx/gitlab where there is a section
upstream gitlab-workhorse {
  server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;
}

and a
proxy_pass http://gitlab-workhorse;

at the end of the configuration.
I'm currently digging into the same issue and will report back, when I've solved it.


[System] You are a helpful assistant.

[User]
Install gitk on Mac
How can I install gitk on a Mac?
From their official website, it seems gitk comes with Git, but the version of my Git (git version 1.7.12.4 (Apple Git-37)) does not come with gitk.
brew install gitk does not work for gitk.
Version information (copied from comments):

OS X v10.8.2 (12C2034) (Mountain Lion)
Xcode version 4.6 (4H127)

[Assistant]
Correct, the 1.7.12.4 (Apple Git-37) does not come with gitk. You can install a more recent version of Git + git-ui as a separate formula by using Homebrew (executable brew).  More thorough instructions are located on The fastest and easiest way to install Ruby on a Mac in 2022 (see this commit extracting git-gui/gitk into its own formula: git-gui: split from git formula.)
Run the following commands at the terminal:
brew update
brew install git
brew install git-gui

If you get an error indicating it could not link Git, then you may need to change permissions/owners of the files it mentions.
Once completed, run:
type -a git

And make sure it shows:
/usr/local/bin/git

If it does not, run:
brew doctor

And make the path change to put /usr/local/bin earlier in the path. Now, gitk should be on your path (along with an updated version of Git).


[System] You are a helpful assistant.

[User] git-bundle - Move objects and refs by archive

[Assistant]
OBJECT PREREQUISITES When creating bundles it is possible to create a self-contained bundle
that can be unbundled in a repository with no common history, as well
as providing negative revisions to exclude objects needed in the
earlier parts of the history. Feeding a revision such as new to git bundle create will create a
bundle file that contains all the objects reachable from the revision new . That bundle can be unbundled in any repository to obtain a full
history that leads to the revision new : $ git bundle create full.bundle new A revision range such as old..new will produce a bundle file that
will require the revision old (and any objects reachable from it)
to exist for the bundle to be "unbundle"-able: $ git bundle create full.bundle old..new A self-contained bundle without any prerequisites can be extracted
into anywhere, even into an empty repository, or be cloned from
(i.e., new , but not old..new ). It is okay to err on the side of caution, causing the bundle file
to contain objects already in the destination, as these are ignored
when unpacking at the destination. If you want to match git clone --mirror , which would include your
refs such as refs/remotes/* , use --all .
If you want to provide the same set of refs that a clone directly
from the source repository would get, use --branches --tags for
the <git-rev-list-args> . The git bundle verify command can be used to check whether your
recipient repository has the required prerequisite commits for a
bundle.


[System] You are a helpful assistant.

[User] git-read-tree - Reads tree information into the index  --prefix=<prefix>

[Assistant]
Keep the current index contents, and read the contents
of the named tree-ish under the directory at <prefix> .
The command will refuse to overwrite entries that already
existed in the original index file.


[System] You are a helpful assistant.

[User]
Force add despite the .gitignore file
Is there a way to force git to add a file despite the .gitignore file?

[Assistant]
See man git-add:
   -f, --force
       Allow adding otherwise ignored files.

So run this
git add --force my/ignore/file.foo


[System] You are a helpful assistant.

[User]
What is the format of <pattern> in git-branch --list
As title, I have read the manual but in vain.
What I found is that a * can be wildcard pattern matching.
git branch --list 'issues*6'
 issues/586
 issues/616

However, it's found by myself instead of mentioned in manual page.
I wonder what is the real format of <pattern>.

[Assistant]
Quoting from that same manual page you linked:

If --list is given, or if there are no non-option arguments, existing branches are listed; the current branch will be highlighted with an asterisk. Option -r causes the remote-tracking branches to be listed, and option -a shows both local and remote branches. If a <pattern> is given, it is used as a shell wildcard to restrict the output to matching branches. If multiple patterns are given, a branch is shown if it matches any of the patterns. Note that when providing a <pattern>, you must use --list; otherwise the command is interpreted as branch creation.

So the answer, at least according to the documentation, is that "it is used as a shell wildcard".  This assumes, of course, that you know what the phrase "shell wildcard" means—and more importantly, it's wrong, since a straight shell wildcard would not match across the /.
The documentation should say something like: "The pattern acts much like a shell wildcard / glob pattern, except that slashes are not treated specially, so that a*b matches both accb and ac/cb, and a[bc/]* matches all of a/d, abcd, ac/cb, and accb."
Examples:
$ git branch -a
  a/d
  abcd
  ac/cb
  accb
* master
$ git branch --list 'a*b'
  ac/cb
  accb
$ git branch --list 'a[bc/]*'
  a/d
  abcd
  ac/cb
  accb
$


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-prune-packed

[Assistant] Remove extra objects that are already in pack files


[System] You are a helpful assistant.

[User]
How to find/identify large commits in git history?
I have a 300 MB git repo. The total size of my currently checked-out files is 2 MB, and the total size of the rest of the git repo is 298 MB. This is basically a code-only repo that should not be more than a few MB.
I suspect someone accidentally committed some large files (video, images, etc), and then removed them... but not from git, so the history still contains useless large files. How can find the large files in the git history? There are 400+ commits, so going one-by-one is not practical.
NOTE: my question is not about how to remove the file, but how to find it in the first place.

[Assistant]
A blazingly fast shell one-liner
This shell script displays all blob objects in the repository, sorted from smallest to largest.
For my sample repo, it ran about 100 times faster than the other ones found here.
On my trusty Athlon II X4 system, it handles the Linux Kernel repository with its 5.6 million objects in just over a minute.
The Base Script
git rev-list --objects --all |
  git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
  sed -n 's/^blob //p' |
  sort --numeric-sort --key=2 |
  cut -c 1-12,41- |
  $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

When you run above code, you will get nice human-readable output like this:
...
0d99bb931299  530KiB path/to/some-image.jpg
2ba44098e28f   12MiB path/to/hires-image.png
bd1741ddce0d   63MiB path/to/some-video-1080p.mp4

The first column is the ID of the file (blob object) in the Git object database. To find the commit(s) that contain the file, see Which commit has this blob? .
macOS users: Since numfmt is not available on macOS, you can either omit the last line and deal with raw byte sizes or brew install coreutils.
Filtering
To achieve further filtering, insert any of the following lines before the sort line.
To exclude files that are present in HEAD, insert the following line:
grep -vF --file=<(git ls-tree -r HEAD | awk '{print $3}') |

To show only files exceeding given size (e.g. 1 MiB = 220 B), insert the following line:
awk '$2 >= 2^20' |

Output for Computers
To generate output that's more suitable for further processing by computers, omit the last two lines of the base script. They do all the formatting. This will leave you with something like this:
...
0d99bb93129939b72069df14af0d0dbda7eb6dba 542455 path/to/some-image.jpg
2ba44098e28f8f66bac5e21210c2774085d2319b 12446815 path/to/hires-image.png
bd1741ddce0d07b72ccf69ed281e09bf8a2d0b2f 65183843 path/to/some-video-1080p.mp4

Appendix
File Removal
For the actual file removal, check out this SO question on the topic.
Understanding the meaning of the displayed file size
What this script displays is the size each file would have in the working directory. If you want to see how much space a file occupies if not checked out, you can use %(objectsize:disk) instead of %(objectsize). However, mind that this metric also has its caveats, as is mentioned in the documentation.
More sophisticated size statistics
Sometimes a list of big files is just not enough to find out what the problem is. You would not spot directories or branches containing humongous numbers of small files, for example.
So if the script here does not cut it for you (and you have a decently recent version of git), look into git-filter-repo --analyze or git rev-list --disk-usage (examples).


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  diff.external

[Assistant]
If this config variable is set, diff generation is not
performed using the internal diff machinery, but using the
given command.  Can be overridden with the ‘GIT_EXTERNAL_DIFF’
environment variable.  The command is called with parameters
as described under "git Diffs" in git .  Note: if
you want to use an external diff program only on a subset of
your files, you might want to use gitattributes instead.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --submodule[=<format>]

[Assistant]
Specify how differences in submodules are shown.  When specifying --submodule=short the short format is used.  This format just
shows the names of the commits at the beginning and end of the range.
When --submodule or --submodule=log is specified, the log format is used.  This format lists the commits in the range like git-submodule summary does.  When --submodule=diff is specified, the diff format is used.  This format shows an
inline diff of the changes in the submodule contents between the
commit range.  Defaults to diff.submodule or the short format
if the config option is unset.


[System] You are a helpful assistant.

[User]
git archive fatal: Operation not supported by protocol
I'm trying to checkout part of remote git repository. As recommended here, with help of command
git archive --format=zip --remote=http://path_to_repository

But I'm getting error message:
fatal: Operation not supported by protocol.
Unexpected end of command stream

Git is not supporting this operation with http protocol? Thats a problem of hosting environment or git itself? Any directions would help, thanks.

[Assistant]
git archive can work with a server with git protocol support (i.e. git server, smart-http and ssh server).
In your case, either your git is too old, or the server is dumb http server (normal http server, without "smart" git support). You need to clone the repository and archive from there.


[System] You are a helpful assistant.

[User] git-update-index - Register file contents in the working tree to the index  --force-untracked-cache

[Assistant]
Same as --untracked-cache . Provided for backwards
compatibility with older versions of Git where --untracked-cache used to imply --test-untracked-cache but
this option would enable the extension unconditionally.


[System] You are a helpful assistant.

[User] git-push - Update remote refs along with associated objects  from

[Assistant]
The name of the local ref being pushed, minus its refs/<type>/ prefix. In the case of deletion, the
name of the local ref is omitted.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  GIT_PRINT_SHA1_ELLIPSIS (deprecated)

[Assistant]
If set to yes , print an ellipsis following an
(abbreviated) SHA-1 value.  This affects indications of
detached HEADs ( git-checkout ) and the raw
diff output ( git-diff ).  Printing an
ellipsis in the cases mentioned is no longer considered
adequate and support for it is likely to be removed in the
foreseeable future (along with the variable).


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-count-objects

[Assistant] Count unpacked number of objects and their disk consumption


[System] You are a helpful assistant.

[User] git-send-email - Send a collection of patches as emails  --quiet

[Assistant]
Make git-send-email less verbose.  One line per email should be
all that is output.


[System] You are a helpful assistant.

[User]
Redo merge of just a single file
I'm in the middle of a large merge, and I've used git mergetool to resolve all the conflicts, but I have not committed yet, as I wanted to make sure the merge was ok first.
It turns out that I made a mistake while resolving the conflicts in one file, and I would like to redo the conflict resolution with git mergetool on that file. As this is a large merge I would like to avoid redoing the merge on all the other files, as I understand I would have to do with git merge --abort.
I know I could just edit the file manually, but this would be quite tedious and it would be much easier to just redo the git mergetool operation. Is this possible?

[Assistant]
It seems I was just looking in the wrong place. The solution turned out to be quite simple.
git checkout -m <file>

This returns the file to its conflicted state. I can then run git mergetool to redo the merge.


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  pickaxe

[Assistant]
The term pickaxe refers to an option to the diffcore
routines that help select changes that add or delete a given text
string. With the --pickaxe-all option, it can be used to view the full changeset that introduced or removed, say, a
particular line of text. See git-diff .


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  --name-status

[Assistant]
Show only names and status of changed files. See the description
of the --diff-filter option on what the status letters mean.
Just like --name-only the file names are often encoded in UTF-8.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --cumulative

[Assistant] Synonym for --dirstat=cumulative


[System] You are a helpful assistant.

[User]
How do I remove msysgit's right click menu options?
This isn't the best programming question but lets face it, the server fault guys aren't well versed in git, so I think its more towards this audience.
I want to switch to TortoiseGit, or PortableGit in my shell, but I'm left with these annoying context-menu options.
How do I get them to go away? Do I have to write a script to uninstall them?

[Assistant]
64-Bit Windows
From a cmd.exe window, run these commands:

cd "C:\Program Files (x86)\Git\git-cheetah"
regsvr32 /u git_shell_ext64.dll

32-Bit Windows
From a cmd.exe window, run these commands

cd "C:\Program Files\Git\git-cheetah"
regsvr32 /u git_shell_ext.dll

Windows 10
If you are on Windows 10 and the previous methods did not work try to uninstall the application and reinstall it. But be careful during the installation process unchecking Windows explorer integration


[System] You are a helpful assistant.

[User] git-rev-parse - Pick out and massage parameters  --disambiguate=<prefix>

[Assistant]
Show every object whose name begins with the given prefix.
The <prefix> must be at least 4 hexadecimal digits long to
avoid listing each and every object in the repository by
mistake.


[System] You are a helpful assistant.

[User] git-add - Add file contents to the index  add.ignoreErrors  add.ignore-errors (deprecated)

[Assistant]
Tells git add to continue adding files when some files cannot be
added due to indexing errors. Equivalent to the --ignore-errors option of git-add . add.ignore-errors is deprecated,
as it does not follow the usual naming convention for configuration
variables.


[System] You are a helpful assistant.

[User] git-ls-files - Show information about files in the index and the working tree  -d  --deleted

[Assistant] Show files with an unstaged deletion


[System] You are a helpful assistant.

[User]
Git stash uncached: how to put away all unstaged changes?
Suppose two set of changes are made in a project versioned by git. One set is staged and the other is not.
I would like to recheck staged changes by running my project at this state (before commit). What is a simple way to put away all unstaged changes and leave only staged? So I need unstaged changes to disappear from my project, but to be stored somewhere for further work.
This is sounds very much like git stash command. But git stash would put both unstaged and staged changes away from my project. And I can't find something like git stash uncached.

[Assistant]
Update 2:
I'm not sure why people are complaining about this answer, it seems to be working perfectly with me, for the untracted files you can add the -u flag
The full command becomes git stash --keep-index -u
And here's a snippet from the git-stash help

If the --keep-index option is used, all changes already added to the
  index are left intact.
If the --include-untracked option is used, all untracked files are
  also stashed and then cleaned up with git clean, leaving the working
  directory in a very clean state. If the --all option is used instead
  then the ignored files are stashed and cleaned in addition to the
  untracked files.

And this is a gif of how it looks:

Update:

Even though this is the selected answer, a lot have pointed out that the [answer below](https://stackoverflow.com/a/34681302/292408) is the correct one, I recommend checking it out.
I tested my answer again today (31/1/2020) against git version 2.24.0, and I still believe that it's correct, I added a small note above about the untracked files.
If you think it's not working please also mention your git version.
Old answer:
If the --keep-index option is used, all changes already added to the index are left intact:
git stash --keep-index

From the documentation of git-stash:

Testing partial commits
You can use git stash save --keep-index when you want to make two or
  more commits out of the changes in the work tree, and you want to test
  each change before committing:
# ... hack hack hack ...
$ git add --patch foo            # add just first part to the index
$ git stash save --keep-index    # save all other changes to the stash
$ edit/build/test first part
$ git commit -m 'First part'     # commit fully tested change
$ git stash pop                  # prepare to work on all other changes
# ... repeat above five steps until one commit remains ...
$ edit/build/test remaining parts
$ git commit foo -m 'Remaining parts'

But, if you just want to visually check the staged changes only, you can try difftool:
git difftool --cached


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  git-diff-index <tree-ish>

[Assistant] compares the <tree-ish> and the files on the filesystem.


[System] You are a helpful assistant.

[User]
How to see all local commits which are not pushed to the remote branch?
I am using the following commands to see all the local commits which are not pushed to remote branch but I am not getting all those local commits.
 git log
 git log origin/master..master

I want to see at-least 10 local commits(only local).

[Assistant]
This will show you all not pushed commits from all branches
git log --branches --not --remotes

and this will show you all your local commits of branch main
git log origin/main..main


[System] You are a helpful assistant.

[User] git - the stupid content tracker  gitformat-bundle

[Assistant] The bundle file format


[System] You are a helpful assistant.

[User]
How can I get a list of Git branches, ordered by most recent commit?
I want to get a list of all the branches in a Git repository with the "freshest" branches at the top, where the "freshest" branch is the one that's been committed to most recently (and is, therefore, more likely to be one I want to pay attention to).
Is there a way I can use Git to either (a) sort the list of branches by latest commit, or (b) get a list of branches together with each one's last-commit date, in some kind of machine-readable format?
Worst case, I could always run git branch to get a list of all the branches, parse its output, and then git log -n 1 branchname --format=format:%ci for each one, to get each branch's commit date. But this will run on a Windows box, where spinning up a new process is relatively expensive, so launching the Git executable once per branch could get slow if there are a lot of branches. Is there a way to do all this with a single command?

[Assistant]
Use the --sort=-committerdate option of git for-each-ref;
Also available since Git 2.7.0 for git branch:
Basic Usage:
git for-each-ref --sort=-committerdate refs/heads/

# Or using git branch (since version 2.7.0)
git branch --sort=-committerdate  # DESC
git branch --sort=committerdate  # ASC

Result:

Advanced Usage:
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'

Result:

Pro Usage (Unix):
You can put the following snippet in your ~/.gitconfig. The recentb alias accepts two arguments:

refbranch: which branch the ahead and behind columns are calculated against. Default master
count: how many recent branches to show. Default 20

[alias]
    # ATTENTION: All aliases prefixed with ! run in /bin/sh make sure you use sh syntax, not bash/zsh or whatever
    recentb = "!r() { refbranch=$1 count=$2; git for-each-ref --sort=-committerdate refs/heads --format='%(refname:short)|%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always --count=${count:-20} | while read line; do branch=$(echo \"$line\" | awk 'BEGIN { FS = \"|\" }; { print $1 }' | tr -d '*'); ahead=$(git rev-list --count \"${refbranch:-origin/master}..${branch}\"); behind=$(git rev-list --count \"${branch}..${refbranch:-origin/master}\"); colorline=$(echo \"$line\" | sed 's/^[^|]*|//'); echo \"$ahead|$behind|$colorline\" | awk -F'|' -vOFS='|' '{$5=substr($5,1,70)}1' ; done | ( echo \"ahead|behind|branch|lastcommit|message|author\n\" && cat) | column -ts'|';}; r"

Result:


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  ignore-all-space

[Assistant]
Ignore whitespace when comparing lines. This ignores differences
even if one line has whitespace where the other line has none.


[System] You are a helpful assistant.

[User]
How to "git show" the diffs for a merge commit?
When I have a merge commit and run git show <commit-ish>, it shows only the commit log, not the the diffs:
commit c0f50178901e09a1237f7b9d9173ec5d1c4936c
Merge: ed234b ded051
Author: abc
Date:   Mon Nov 21 15:56:33 2016 -0800

    Merge branch 'abc'

I understand the real commit is in merge log, but I want to save typing.  Is there a way to show the diff in one?

[Assistant]
Use one of the following:
git show -m c05f017
git show --first-parent c05f017
git diff c05f017^ c05f017

There's a fundamental error in your question: commits are not diffs;  commits are snapshots.  This might seem like a distinction without a difference—and for some commits, it is.  But for merge commits, it's not.
When git show (or git log -p) shows a commit as a diff, it's doing so by comparing the commit's snapshot to something else.  The git diff command does the same thing: it compares one commit to another commit.  (Or it can compare a commit to the work-tree, or to the contents of the index, or a few other combinations as well.)
For ordinary commits, it's trivially obvious what to compare: compare this commit's snapshot to the previous (i.e., parent) commit's snapshot.  So that is what git show does (and git log -p too): it runs a git diff from the parent commit, to this commit.
Merge commits don't have just one parent commit, though.  They have two parents.1  This is what makes them "merge commits" in the first place: the definition of a merge commit is a commit with at least two parents.

1A merge commit can have three or more parents.  These are called "octopus merges".  They don't do anything special, though, and are mainly for showing off. :-)  You can ignore them here.

When there are two parents, which one(s) should git show compare against?
What git log -p chooses to do by default is not to compare at all.  You can make it show something by adding various flags (see below).
What git show chooses to do by default is more complicated.  Since there are two parents, git show first compares against the "first parent",2 then compares against the second parent.  Then—this part is quite crucial—it combines the two diffs, producing a so-called "combined diff".
For the next section, let me note a tricky, but very useful, bit of Git syntax.  If you have a commit ID like c05f017, you can add a caret or "hat" character ^ after that, to name a parent commit.  You can optionally add another number to select which parent.  For regular (non-merge) commits there's only one, so c05f017^ is the parent.  For merge commits, c05f017^ and c05f017^1 both mean the first parent, while c05f017^2 means the second parent.

2I put this in quotes because the first parent idea is especially important in Git, as we will see in a moment.  In other words, Git cares most about which parent is first, while the rest are just "the rest".

Combined diffs
The combined diff format is described in the documentation, but a key bit is first described here, so as to make it especially obscure:3

Note that combined diff lists only files which were modified from all parents.

That is, suppose M is a merge commit, and diffing M^1 vs M says file mainline.txt and common.txt were both changed.  Suppose further that diffing M^2 and M says that file sidebranch.txt and common.txt were both changed.  The combined diff will show only common.txt, skipping both mainline.txt and sidebranch.txt because those two files were only modified from one parent (each).  (Even then Git may show only some of the diffs for common.txt.)

3It took me a long time to find this in the documentation, as I kept looking at the other section.

Splitting the diffs
The -m option—m probably stands for merge here—tells Git to, in effect, "split" the merge.  That is, instead of trying to combine the diffs against each parent into one big combined diff, just show the diff against each parent, one diff at a time.
This is sometimes what you want.  When it's not what you want, you can run your own explicit git diff to just diff against one of the two parents (or see below).
Which parent should you diff against?
Usually, the correct answer is "the first parent".
The key to the "first parent" notion is that when Git makes a merge commit, it always records the branch you're on at the time, as the first parent.  The other branch becomes the second parent.
That is, if you're on develop and you merge topic:
$ git checkout develop
$ git merge topic

Git will make a new commit—a merge commit, with two parents—on your current branch, develop.  The first parent of the merge commit will be the commit that was the tip of develop just a moment ago.  The second parent will be the commit that is (still) the tip of topic.
Since you're usually concerned with what the merge brought in, comparing against the first parent will give you that.  So usually that's what you want.  For this reason, git show allows you to run git show --first-parent.  That "splits" the commit and then git show only diffs against the first parent.  (This is a bit different than git show -m, which splits the commit twice: the first split compares against the first parent, and the second split compares against the second parent.)
Similarly, you can run git log -p --first-parent Here, the --first-parent flag has an even more important effect: the log operation does not look at any of the side branch's commits at all, only those on the main (first-parent) line.  Note that if your Git is older than 2.31, you still need the -m flag as well (when using git log, that is; git show defaults to --cc and hence does not require the -m, and all of this was cleaned up in Git 2.31).


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  repack.updateServerInfo

[Assistant]
If set to false, git-repack will not run git-update-server-info . Defaults to true. Can be overridden
when true by the -n option of git-repack .


[System] You are a helpful assistant.

[User]
Connect an issue with a commit after the commit

I did a git commit and pushed to github, but forgot to mention the issue number in the commit (I forgot to write something like ... closes #123).
If I had mentioned the issue number in the commit message, github would have connected the commit to the issue. Is there any way to do this after the commit, when it's too late for me to change the commit message?
EDIT: Assume that it's too late to amend the commit or otherwise alter the history. I am really asking about github functionality, not git.

[Assistant]
In your issue on GitHub, just write a comment with the commit hash. For instance:
Fixed with commit 61d949320fc0bf1a8dba09b3845bddcd153b1a64

GitHub will recognize it as a SHA and link to the right commit page.


[System] You are a helpful assistant.

[User] git-fast-import - Backend for fast Git data importers  --max-pack-size=<n>

[Assistant]
Maximum size of each output packfile.
The default is unlimited.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  ignore-space-at-eol

[Assistant] Ignore changes in whitespace at EOL.


[System] You are a helpful assistant.

[User] git-commit - Record changes to the repository  --

[Assistant] Do not interpret any more arguments as options.


[System] You are a helpful assistant.

[User]
How to commit my current changes to a different branch in Git [duplicate]
This question already has answers here:

How do I merge my local uncommitted changes into another Git branch?

                                (9 answers)

Closed 9 years ago.

Sometimes it happens that I make some changes in my working directory, and I realize that these changes should be committed in a branch different to the current one. This usually happens when I want to try out new things or do some testing and I forget to create a new branch beforehand, but I don't want to commit dirty code to the master branch.
So, how can I make that uncommitted changes (or changes stored in the index) be committed to a different branch than the current one?

[Assistant]
The other answers suggesting checking out the other branch, then committing to it, only work if the checkout is possible given the local modifications. If not, you're in the most common use case for git stash:
git stash
git checkout other-branch
git stash pop

The first stash hides away your changes (basically making a temporary commit), and the subsequent stash pop re-applies them. This lets Git use its merge capabilities.
If, when you try to pop the stash, you run into merge conflicts... the next steps depend on what those conflicts are. If all the stashed changes indeed belong on that other branch, you're simply going to have to sort through them - it's a consequence of having made your changes on the wrong branch.
On the other hand, if you've really messed up, and your work tree has a mix of changes for the two branches, and the conflicts are just in the ones you want to commit back on the original branch, you can save some work. As usual, there are a lot of ways to do this. Here's one, starting from after you pop and see the conflicts:
# Unstage everything (warning: this leaves files with conflicts in your tree)
git reset

# Add the things you *do* want to commit here
git add -p     # or maybe git add -i
git commit

# The stash still exists; pop only throws it away if it applied cleanly
git checkout original-branch
git stash pop

# Add the changes meant for this branch
git add -p
git commit

# And throw away the rest
git reset --hard

Alternatively, if you realize ahead of the time that this is going to happen, simply commit the things that belong on the current branch. You can always come back and amend that commit:
git add -p
git commit
git stash
git checkout other-branch
git stash pop

And of course, remember that this all took a bit of work, and avoid it next time, perhaps by putting your current branch name in your prompt by adding $(__git_ps1) to your PS1 environment variable in your bashrc file. (See for example the Git in Bash documentation.)


[System] You are a helpful assistant.

[User]
Download Github pull request as unified diff
How can I download the changes contained in a Github pull request as a unified diff?

[Assistant]
To view a commit as a diff/patch file, just add .diff or .patch to the end of the URL, for example:

https://github.com/weppos/whois/pull/90
https://github.com/weppos/whois/pull/90.diff
https://github.com/weppos/whois/pull/90.patch


[System] You are a helpful assistant.

[User] git-archive - Create an archive of files from a named tree  git archive --prefix=git-1.4.0/ -o git-1.4.0.tar.gz v1.4.0

[Assistant] Same as above, but the format is inferred from the output file.


[System] You are a helpful assistant.

[User] git-svn - Bidirectional operation between a Subversion repository and Git  svn.pathnameencoding

[Assistant]
This instructs git svn to recode pathnames to a given encoding.
It can be used by windows users and by those who work in non-utf8
locales to avoid corrupted file names with non-ASCII characters.
Valid encodings are the ones supported by Perl’s Encode module.


[System] You are a helpful assistant.

[User]
Does gitlab API have a rate limit

github has a rate limit of 5000/hour for OAuth client, but I can't find the same information from gitlab (apart from 6/minute for creating new users and resetting password), does it mean there's no limit?

[Assistant]
The answer is no longer "no", at least on gitlab.com:

We enabled capacity limiting on GitLab.com to reduce impact of GitLab Runners on stability of GitLab.

Now each API response has the following headers:
RateLimit-Limit: 600
RateLimit-Observed: 12
RateLimit-Remaining: 588

From this issue, it looks like the limit is 10 requests per second per IP address.


[System] You are a helpful assistant.

[User]
Is there a way to disable "remove source branch" default option?

We are working on Gitlab and each time I start merging a branch, Gitlab makes the option "Remove source branch" checked by default (which is -I think- dangerous).

As I don't guarantee that me or a colleague can forget to uncheck this option and make the mistake of removing the branch, I'm wondering if there is a solution to make it unchecked by default (which is -I think- will be more secure)?

[Assistant]
Go to Settings > General > Merge requests
Uncheck the box: Enable 'Delete source branch' option by default

This option is only available for the maintaniner role.


[System] You are a helpful assistant.

[User]
Gitlab: There has been a runner system failure

I use Gitlab for doing Continuous Integration and Development and all of a sudden I get this error message "There has been a runner system failure, please try again"

There's no real error message or error code.
I've tried restarting the gitlab runner, using gitlab-runner restart, I've done a reboot of the server its running on but I keep getting this error message on Gitlab whenever I push a code change.

[Assistant]
After a couple of hours, I realized the issue is that the server that Gitlab Runner is running on has no space left.
I logged into the server in question.  Looked at the Gitlab log file using the following command:
journalctl -u gitlab-runner
And it showed me the following logs:
May 21 08:20:41 gitlab-runner[18936]: Checking for jobs... received                       job=178911 repo_url=https://.......git runner=f540b942
May 21 08:20:41 gitlab-runner-01 gitlab-runner[18936]: WARNING: Failed to process runner                   builds=0 error=open /tmp/trace543210445: no space left on device executor=docker runner=f540b942

To fix this issue I ran the docker container prune command which clears out stopped containers.
Alternatively you could use the docker system prune command which would remove all unused objects.
See https://linuxize.com/post/how-to-remove-docker-images-containers-volumes-and-networks/ for more information about those docker commands.
Afterwards, I no longer got the error on Gitlab when pushing changes.


[System] You are a helpful assistant.

[User]
Gitlab CI fails with ERROR: Job failed: exit code 1

I am pretty new to gitlab ci and I have a project with a pre-existing gitlab configuration which was running fine but after pushing a few code changes, it has now completely stopped working and I can't figure out why. Here is the .gitlab-ci.yml
stages:
  - build
  - deploy

variables:
  DOCKER_HOST: tcp://localhost:2375

assets:
  stage: build
  image: node:10-alpine
  script:
    - npm ci
    - NODE_ENV=production npm run build
  artifacts:
    expire_in: 1 day
    paths:
      - public/assets
  tags:
    - docker

package:
  stage: deploy
  image: php:7.3-cli-alpine
  dependencies:
    - assets
  before_script:
    - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    - php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    - php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    - php -r "unlink('composer-setup.php');"
  script:
    - composer install --prefer-dist --no-progress --optimize-autoloader --no-scripts
    - rm -fr .git
  artifacts:
    expire_in: 1 day
    paths:
      - .
  tags:
    - docker

docker:
  stage: deploy
  image: docker:latest
  services:
    - docker:18-dind
  dependencies:
    - assets
  script:
    - docker build -t $CI_REGISTRY_IMAGE:latest .
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker push $CI_REGISTRY_IMAGE:latest
  only:
    - master
  tags:
    - docker

deploy:
  stage: deploy
  image: php:7.3-cli-alpine
  dependencies:
    - assets
  before_script:
    - curl -LO https://deployer.org/deployer.phar
    - mv deployer.phar /usr/local/bin/dep
    - chmod +x /usr/local/bin/dep
    - apk add --update openssh rsync
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - ssh-keyscan -t rsa domain.co.uk >> /root/.ssh/known_hosts
  script:
    - dep deploy -p --tag="$CI_COMMIT_TAG"
  only:
    - tags
  tags:
    - docker

I am consistently getting the following error and I am wondering what has changed and if it is the server or gitlab-ci causing the following issue. I checked the server and it's running fine but there is no docker installed there and I presume the docker is not supposed to be installed on the server for what it is trying to do anyways?
Checking out a50d58fd as master...
 Skipping Git submodules setup
Downloading artifacts for assets (447059035)...
00:01
 Downloading artifacts from coordinator... ok        id=447059035 responseStatus=200 OK token=cp4GCzgJ
$ docker build -t $CI_REGISTRY_IMAGE:latest .
00:02
 time="2020-02-24T03:53:41Z" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial tcp [::1]:2375: connect: connection refused"
 error during connect: Post http://localhost:2375/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=sja0dvuf6gm0w8tneigulo3ha&shmsize=0&t=registry.gitlab.com%2Fnir.npl%2Fbrayleys-honda%3Alatest&target=&ulimits=null&version=1: context canceled
 ERROR: Job failed: exit code 1

[Assistant]
Check if this is similar to this thread from a year ago:

It seems docker updated their latest stable images and gitlab has not updated their runners yet, changing the images to be on the 18 major fixes these issues, eg:

image: docker:18-git

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2

services:
  - docker:18-dind

In you case, a year later, that would be docker:19-dind, especially if you are using image: docker:latest, which is not a good practice, because "latest" can vary at any time.
image: docker:19-git would be preferable.


[System] You are a helpful assistant.

[User] git-commit - Record changes to the repository  commit.verbose

[Assistant]
A boolean or int to specify the level of verbosity with git commit .
See git-commit .


[System] You are a helpful assistant.

[User]
Add emphasis github flavored markdown within code block

Is it possible to bold a portion of text within a code block in a github readme?

[Assistant]
This answer on StackExchange Meta works on Github too:
Use a <pre> tag (or <pre><code>) instead of ```, and use <b> tags around the part you want bold.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --combined-all-paths

[Assistant]
This flag causes combined diffs (used for merge commits) to
list the name of the file from all parents.  It thus only has
effect when --diff-merges=[dense-]combined is in use, and
is likely only useful if filename changes are detected (i.e.
when either rename or copy detection have been requested).


[System] You are a helpful assistant.

[User]
What is `git restore` and how is it different from `git reset`?
When I want to unstage a staged file, all of my Git tutorials show something like:
$ git add *
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    renamed:    README.md -> README
    modified:   CONTRIBUTING.md

This hint tells us to use git reset for unstaging a staged file.
But instead, in my terminal, I see:
git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    renamed:    cat.js -> catcat.js
    renamed:    tolendo.gogo -> tolendo.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    readme (copy).md
    tolendo (copy).txt
    zing (copy).html

My terminal tells me to use git restore --staged but the tutorials, as well as Git’s website, tell me to use git reset HEAD.
I have no idea about the new restore command. I tried Google to find the difference between git reset and git restore but nothing seemed to fit my question.

[Assistant]
I have presented git restore (which is still marked as "experimental") in "How to reset all files from working directory but not from staging area?", with the recent Git 2.23 (August 2019).
It helps separate git checkout into two commands:

one for files (git restore), which can cover git reset cases.
one for branches (git switch, as seen in "Confused by git checkout"), which deals only with branches, not files.

As reset, restore and revert documentation states:

There are three commands with similar names: git reset, git restore and git revert.

git-revert is about making a new commit that reverts the changes made by other commits.
git-restore is about restoring files in the working tree from either the index or another commit.
  This command does not update your branch.
  The command can also be used to restore files in the index from another commit.
git-reset is about updating your branch, moving the tip in order to add or remove commits from the branch. This operation changes the commit history.
git reset can also be used to restore the index, overlapping with git restore.

So:

To restore a file in the index to match the version in HEAD (this is the same as using git-reset)
git restore --staged hello.c

or you can restore both the index and the working tree (this the same as using git-checkout)
git restore --source=HEAD --staged --worktree hello.c

or the short form which is more practical but less readable:
git restore -s@ -SW hello.c

With Git 2.25.1 (Feb. 2020), "git restore --staged" did not correctly update the cache-tree structure, resulting in bogus trees to be written afterwards, which has been corrected.
See discussion.
See commit e701bab (08 Jan 2020) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 09e393d, 22 Jan 2020)

restore: invalidate cache-tree when removing entries with --staged
Reported-by: Torsten Krah
Signed-off-by: Jeff King
When "git restore --staged " removes a path that's in the index, it marks the entry with CE_REMOVE, but we don't do anything to invalidate the cache-tree.
  In the non-staged case, we end up in checkout_worktree(), which calls remove_marked_cache_entries(). That actually drops the entries from the index, as well as invalidating the cache-tree and untracked-cache.
But with --staged, we never call checkout_worktree(), and the CE_REMOVE entries remain. Interestingly, they are dropped when we write out the index, but that means the resulting index is inconsistent: its cache-tree will not match the actual entries, and running "git commit" immediately after will create the wrong tree.
We can solve this by calling remove_marked_cache_entries() ourselves before writing out the index. Note that we can't just hoist it out of checkout_worktree(); that function needs to iterate over the CE_REMOVE entries (to drop their matching worktree files) before removing them.
One curiosity about the test: without this patch, it actually triggers a BUG() when running git-restore:
BUG: cache-tree.c:810: new1 with flags 0x4420000 should not be in cache-tree

But in the original problem report, which used a similar recipe, git restore actually creates the bogus index (and the commit is created with the wrong tree). I'm not sure why the test here behaves differently than my out-of-suite reproduction, but what's here should catch either symptom (and the fix corrects both cases).

With Git 2.27 (Q2 2020), "git restore --staged --worktree" now defaults to take the contents out of "HEAD", instead of erring out.
See commit 088018e (05 May 2020) by Eric Sunshine (sunshineco).
(Merged by Junio C Hamano -- gitster -- in commit 4c2941a, 08 May 2020)

restore: default to HEAD when combining --staged and --worktree
Signed-off-by: Eric Sunshine
Reviewed-by: Taylor Blau
By default, files are restored from the index for --worktree, and from HEAD for --staged.
When --worktree and --staged are combined, --source must be specified to disambiguate the restore source, thus making it cumbersome to restore a file in both the worktree and the index.
(Due to an oversight, the --source requirement, though documented, is not actually enforced.)
However, HEAD is also a reasonable default for --worktree when combined with --staged, so make it the default anytime --staged is used (whether combined with --worktree or not).

So now, this works:
git restore --staged --worktree
git restore -SW


[System] You are a helpful assistant.

[User]
Edit a merge commit with git rebase
In Git when I have commits eg. A - B - C and I want to edit the B commit, I

use git rebase -i <A-commit-hash>,
in the list I write edit command in front of B commit,
git rebase stops right after B commit so I can fix anything I want using git commit --amend,
and then I continue using git rebase --continue.

As far as I know this is the best practice how to do this. With this method I can edit any commit in the past (as long as it hasn't been pushed to remote branch yet), and moreover with -p flag I can even preserve the merges. This is just great.
My current problem is: I did a mistake (typo) on one line in a merge commit (while resolving a conflict when merging two branches).
I'd like to fix it but I don't know how to make git rebase to stop at a merge commit. The git rebase -p -i <blah> list ignores merge commits, so I cannot write edit command in front of it and make the git rebase stop there to let me edit it.
Any help please?
I just want to fix this line in the merge commit while preserving all the commits (and merges) after it.
Thanks.

[Assistant]
Updated answer for 2020:
You can force git rebase -i to stop at the merge commit via the break command (added in Git 2.20). You can then edit the merge commit as desired via git commit --amend.
Detailed steps:

Run git rebase -i --rebase-merges $ancestor_of_merge_commit
Find the merge commit you want to edit in the todo list.
Insert a new line after the merge commit that contains only break (or b).
Save your changes and exit your editor. Git rebase will check out the merge commit, print something like the following, then return you to your prompt:
Stopped at fb91fab (Merge branch 'foo' into bar)

Use git commit --amend to edit the merge commit as desired.
Run git rebase --continue when you are done editing the merge commit.

Alternative approach if you do not have any merge commits after the commit you want to edit:

Run git rebase -i $id_of_merge_commit
Insert a new line at the top of the todo list that contains only break (or b).
Save your changes and exit your editor. Git rebase will check out the merge commit, print something like the following, then return you to your prompt:
Stopped at fb91fab (Merge branch 'foo' into bar)

Use git commit --amend to edit the merge commit as desired.
Run git rebase --continue when you are done editing the merge commit.

Original answer from 2012 (pre-break):
Git does not make it easy to do interactive rebases when merges are involved.  The -p option uses the -i mechanism internally, so mixing the two doesn't really work.
However, git rebase is just an automated way to do lots of cherry-picks.  You can replicate its behavior by manually cherry-picking to get a bit more control over the process.  It's less convenient and more prone to human error, but possible.
This is the approach I suggest:

use git rebase to get to the commit after the merge (the child of the merge)
use git reset --hard HEAD^ to manually get to the merge
use git commit --amend to repair the merge
use git cherry-pick to get back to the commit after the merge
use git rebase --continue to finish

Here are the specific steps:

Note the SHA1 ID of the merge commit you want to modify.  For discussion, suppose it is deadbeef.
Note the SHA1 ID of the commit right after the merge commit you want to modify (the merge commit's child).  Suppose it is facef00d.
Run git rebase -i deadbeef.
Select facef00d for editing.
When rebase returns you to a prompt to edit facef00d, run git reset --hard HEAD^.  You should now be at deadbeef (git rev-parse HEAD should print deadbeef).
Make your edits to fix the incorrect merge conflict and use git add to stage them.
Run git commit --amend to fuse the staged fix with the bad merge commit.  The result will now have a different SHA1 (not deadbeef).
Run git cherry-pick facef00d to apply the changes made by facef00d to the fixed merge commit.
Run git rebase --continue to finish.


[System] You are a helpful assistant.

[User] git-fsck - Verifies the connectivity and validity of the objects in the database  gitmodulesBlob

[Assistant] (ERROR) A non-blob found at .gitmodules .


[System] You are a helpful assistant.

[User]
Is there a URL query string for searching own GitHub Gists?

Is there a URL query string for searching only own GitHub Gists? I wouldn't care if it only worked with public Gists.
The only thing I could find is the URL for searching all public Gists, but that's not very helpful for finding own Gists
https://gist.github.com/search?q=hello+world

Ultimate goal: quickly searching for own Gists via launcher tools (in my case Alfred) or Chrome search engine shortcuts.

[Assistant]
Try searching with user:<username> hello world. E.g.
https://gist.github.com/search?q=user%3Adefunkt+hello+world


[System] You are a helpful assistant.

[User]
How to use Git properly with Xcode?
I have been an iphone developer for a while, and I have recently been including git in my workflow.  I have used git settings found on http://shanesbrain.net/2008/7/9/using-xcode-with-git for my workflow so far.
Those settings tell git to exclude *.pbxproj from merges?  Is there a real reason for doing this?  For example, when I add a file to the project and push to origin, my fellow developers will not have that file added to their xcode project when they pull.  Then if one of them builds a release this file may not be included.  Shouldn't I just let git handle the merges for the project file?  Why or why not this file should be in merges and how to properly handle the situation when files are added to the project?

[Assistant]
I have worked on iPhone applications full time since the SDK launch, most of that time spent working on teams with multiple developers.
The truth is that it's way more harmful to disallow merging of that .pbxproj file than it is helpful.  As you say, when you add a file unless other people get that file, they have to also add it to their project - in an application of any size, that sucks and it also takes away a huge benefit of source code control in that you cannot really revert to a complete earlier project state just through git.
The .pbxproj file is simply a property list (similar to XML).  From experience, just about the ONLY merge conflict you were ever get is if two people have added files at the same time.  The solution in 99% of the merge conflict cases is to keep both sides of the merge, which for git at least simply involves removing any >>>>, <<<<, and ==== lines.  In fact this is so common that I have created a simple shell script to fix a .pbxproj file in a merge state from git, I run this from within the project directory (at the Classes level):
#!/bin/sh

    projectfile=`find -d . -name 'project.pbxproj'`
    projectdir=`echo *.xcodeproj`
    projectfile="${projectdir}/project.pbxproj"
    tempfile="${projectdir}/project.pbxproj.out"
    savefile="${projectdir}/project.pbxproj.mergesave"

    cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
    cp $projectfile $savefile
    mv $tempfile $projectfile

Worst case if it fails (you ask XCode to load the project and it fails to load), you simply delete the .pbxproj file, check out the master from git, and re-add your files.  But I've never had that happen in many months of use with this script, again working full time on iPhone applications with several other developers.
Another option (pointed out in comments below) that you can try using in place of the script, is to add this line to a .gitattributes file:
*.pbxproj text -crlf -diff -merge=union

Then git will always take both sides of a merge for the .pbxproject files, having the same effect as the script I provided only without any extra work.
Lastly, here is my complete .gitignore file, showing what I do have it set to ignore as there are a few things you don't want - in my case really just emacs remnants and the whole build directory:
# xcode noise
build/*
*.pbxuser
*.mode1v3
*~

# old skool
.svn

# osx noise
.DS_Store
profile


[System] You are a helpful assistant.

[User] git-log - Show commit logs  notes.displayRef

[Assistant]
Which ref (or refs, if a glob or specified more than once), in
addition to the default set by core.notesRef or GIT_NOTES_REF , to read notes from when showing commit
messages with the git log family of commands. This setting can be overridden with the GIT_NOTES_DISPLAY_REF environment variable, which must be a colon separated list of refs or
globs. A warning will be issued for refs that do not exist,
but a glob that does not match any refs is silently ignored. This setting can be disabled by the --no-notes option to the git
log family of commands, or by the --notes=<ref> option accepted by
those commands. The effective value of "core.notesRef" (possibly overridden by
GIT_NOTES_REF) is also implicitly added to the list of refs to be
displayed.


[System] You are a helpful assistant.

[User] gitattributes - Defining attributes per path  Set to string value "auto"

[Assistant]
When text is set to "auto", Git decides by itself whether the file
is text or binary.  If it is text and the file was not already in
Git with CRLF endings, line endings are converted on checkin and
checkout as described above.  Otherwise, no conversion is done on
checkin or checkout.


[System] You are a helpful assistant.

[User]
How can I display my current git branch name in my PowerShell prompt?
Basically I'm after this but for PowerShell instead of bash.
I use git on windows through PowerShell. If possible, I'd like my current branch name to displayed as part of the command prompt.

[Assistant]
An easier way would be just installing the Powershell module posh-git. It comes out of the box with the desired prompt:

The Prompt
PowerShell generates its prompt by executing a prompt function, if one exists. posh-git defines such a function in profile.example.ps1 that outputs the current working directory followed by an abbreviated git status:
C:\Users\Keith [master]>
By default, the status summary has the following format:
[{HEAD-name} +A ~B -C !D | +E ~F -G !H]

(For installing posh-git I suggest using psget)
If you don't have psget use the following command:
(new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/psget/psget/master/GetPsGet.ps1") | iex

To install posh-git use the command:
Install-Module posh-git
To ensure posh-git loads for every shell, use the Add-PoshGitToProfile command.


[System] You are a helpful assistant.

[User]
GIT get the commit hash prior to a specific commit
git 1.7.1
git show <hash>:<file> gives me the file based on the commit hash provided
I am trying to figure out how to bet the file of the previous commit before the one who's hash I have.
I know I can always use the log to get all hashes and figure out the one i need but that's not a good solution in my case as I am trying to minimise the number of commands I need to do for performance issues.
Was wondering if there is a simple way.

[Assistant]
Use git show HEAD^1. You can replace HEAD with your commit-hash
Edit to take multiple parents into account:
In case you want to see all the parents for a commit hash, you can use git rev-list --parents -n 1 <commithash> or use git show as @Bhaskar suggested in the comments to the question.
There are other ways as well as explained here.


[System] You are a helpful assistant.

[User] git-pull - Fetch from and integrate with another repository or a local branch  diff-algorithm=[patience|minimal|histogram|myers]

[Assistant]
Use a different diff algorithm while merging, which can help
avoid mismerges that occur due to unimportant matching lines
(such as braces from distinct functions).  See also git-diff --diff-algorithm .  Note that ort specifically uses diff-algorithm=histogram , while recursive defaults to the diff.algorithm config setting.


[System] You are a helpful assistant.

[User] git-branch - List, create, or delete branches  -r  --remotes

[Assistant]
List or delete (if used with -d) the remote-tracking branches.
Combine with --list to match the optional pattern(s).


[System] You are a helpful assistant.

[User]
GitLab runner can not resolve host when running pipeline

I have a dockerized GitLab and GitLab Runner installation, with following docker-compose.yml:
version: "3"

services:
  gitlab:
    image: gitlab/gitlab-ee:latest
    container_name: gitlab
    restart: always
    hostname: gitlab
    ports:
      - "45022:22"
      - "45080:80"
      - "45443:443"
    volumes:
      - /srv/gitlab/config:/etc/gitlab
      - /srv/gitlab/logs:/var/log/gitlab
      - /srv/gitlab/data:/var/opt/gitlab

  python-runner:
    image: gitlab/gitlab-runner:latest
    container_name: python-runner
    hostname: python-runner
    volumes:
      - /srv/python-runner/config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - CI_SERVER_URL=http://gitlab/ci
      - RUNNER_TOKEN=myTokenCode
      - RUNNER_DESCRIPTION=Python 2.7.14
      - RUNNER_EXECUTOR=docker
      - DOCKER_IMAGE=python:2.7.14
    restart: always

I have registered the runner:
docker exec -it python-runner gitlab-runner register \
    --non-interactive \
    --url "http://gitlab/" \
    --registration-token "${GITLAB_REGISTRATION_TOKEN}" \
    --description "Python 2.7.14" \
    --executor "docker" \
    --docker-image python:2.7.14

The runner is listed in the Runners list:

I can ping the gitlab host from the python-runner:
» docker exec -it python-runner bash
root@python-runner:/# ping gitlab
PING gitlab (172.20.0.2) 56(84) bytes of data.
64 bytes from gitlab.gitlab_default (172.20.0.2): icmp_seq=1 ttl=64 time=0.112 ms
64 bytes from gitlab.gitlab_default (172.20.0.2): icmp_seq=2 ttl=64 time=0.055 ms
^C
--- gitlab ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.055/0.083/0.112/0.029 ms

But when running the pipeline, it fails:
`fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab/group/project.git/': Could not resolve host: gitlab

How is this possible? How can this be solved?
EDIT
It seems the architecture that I am creating is the following:

gitlab running in gitlab docker container
gitlab runner running in python-runner docker container
docker-compose creates a private network gitlab_default (gitlab is the name of the project), and both the gitlab and python-runner containers can reach it other, by IP and by name.
the python-runner uses the docker executor to spawn containers during CI (in the host?), based on python:2.7.14 as defined. I do not know how gitlab names these containers, let's call it ci-job
the project is cloned in this ci-job container, by issuing a git clone. This fails because the ci-job container can not reach the gitlab container, since it is probably in a different network (default network?)

I have tried to force the python-runner to spawn containers in the same gitlab_default network, by using --docker-network-mode gitlab_default flag as follows:
docker exec -it python-runner gitlab-runner register \
    --non-interactive \
    --tag-list python-2.7.14 \
    --url "http://gitlab" \
    --registration-token "$(GITLAB_REGISTRATION_TOKEN)" \
    --name "Python 2.7.14" \
    --executor "docker" \
    --docker-image python:2.7.14 \
    --docker-network-mode gitlab_default

But it still does not work. I am not sure if that's the right flag, since it is poorly documented.
Two questions:

How can I see the containers that the executor is creating when running CI? Can I enter them and do some debugging there?
What is the relevant parameter to ensure that the containers spawned by the docker executor are in the same network as the gitlab container?

EDIT2
After some idle time, my jobs started working. It seems configuring --docker-network-mode did indeed work as expected.

[Assistant]
I had the same problem with gitlab-runner not able to resolve host names. But we use Gitlab running on Debian server (not docker installation) and runners in Google Cloud connected with VPN.
What worked for me was to add dns addresses to the runners config.toml, like this:
  [runners.docker]
    dns = ["dns-1-ip", "dns-2-ip"]


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  -w  --ignore-all-space

[Assistant]
Ignore whitespace when comparing lines.  This ignores
differences even if one line has whitespace where the other
line has none.


[System] You are a helpful assistant.

[User] git-update-index - Register file contents in the working tree to the index  --unmerged

[Assistant]
If --refresh finds unmerged changes in the index, the default
behavior is to error out.  This option makes git update-index continue anyway.


[System] You are a helpful assistant.

[User]
Export GIT LOG into an Excel file
I have looked into the forum, but with no luck.
Requirement :
Run GIT LOG (format) command and write the results into an Excel File .
I have seen examples wherein with GIT Log command, data can be written into a CSV, but formatting is double the effort.
Any utility or approach would be helpful.
Thanks
Milind

[Assistant]
Git gives your the control on how to format the log output using pretty option. Check this out:
git log --pretty=format:%h,%an,%ae,%s

This prints the log in the format of (hash [abbreviated], author name, author email, subject).
To see the full list of format options:
git help log

And scroll down until you see the list of format options.
To redirect the output, use > redirection operator as follows:
git log --pretty=format:%h,%an,%ae,%s > /path/to/file.csv


[System] You are a helpful assistant.

[User]
Does github keep deleted remote branches in history? If so, can those be restored?

I was wondering if there is a way to restore a remote deleted branch in github. History clearly keeps record of the branch and merges with other branches but I'm not sure if it's possible to restore a deleted branch.
Thanks.

[Assistant]
Yes, it's possible to restore a deleted branch from git.
Find your Commit ID: Search for a branch using git reflog
If you had the branch in your local git repo within the last 30 days, you may be able to find it in the reflog using the following:
git reflog

Search for the branch name in the reflog and note the HEAD{x} point or the commit ID.
Re-create the branch from the Reflog HEAD point:
git checkout -b branch_name HEAD@{27}

Re-create the branch from the commit ID:
You can checkout the commit ID and create a branch off of that commit point:
git checkout -b branch_name <commit id>


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  plain

[Assistant]
Show words as [-removed-] and {+added+} .  Makes no
attempts to escape the delimiters if they appear in the input,
so the output may be ambiguous.


[System] You are a helpful assistant.

[User]
How do you organise multiple git repositories, so that all of them are backed up together?
With SVN, I had a single big repository I kept on a server, and checked-out on a few machines. This was a pretty good backup system, and allowed me easily work on any of the machines. I could checkout a specific project, commit and it updated the 'master' project, or I could checkout the entire thing.
Now, I have a bunch of git repositories, for various projects, several of which are on github. I also have the SVN repository I mentioned, imported via the git-svn command..
Basically, I like having all my code (not just projects, but random snippets and scripts, some things like my CV, articles I've written, websites I've made and so on) in one big repository I can easily clone onto remote machines, or memory-sticks/harddrives as backup.
The problem is, since it's a private repository, and git doesn't allow checking out of a specific folder (that I could push to github as a separate project, but have the changes appear in both the master-repo, and the sub-repos)
I could use the git submodule system, but it doesn't act how I want it too (submodules are pointers to other repositories, and don't really contain the actual code, so it's useless for backup)
Currently I have a folder of git-repos (for example, ~/code_projects/proj1/.git/ ~/code_projects/proj2/.git/), and after doing changes to proj1 I do git push github, then I copy the files into ~/Documents/code/python/projects/proj1/ and do a single commit (instead of the numerous ones in the individual repos). Then do git push backupdrive1, git push mymemorystick etc
So, the question: How do your personal code and projects with git repositories, and keep them synced and backed-up?

[Assistant]
I would strongly advise against putting unrelated data in a given
Git repository.  The overhead of creating new repositories is quite
low, and that is a feature that makes it possible to keep
different lineages completely separate.
Fighting that idea means ending up with unnecessarily tangled history,
which renders administration more difficult and--more
importantly--"archeology" tools less useful because of the resulting
dilution.  Also, as you mentioned, Git assumes that the "unit of
cloning" is the repository, and practically has to do so because of
its distributed nature.
One solution is to keep every project/package/etc. as its own bare
repository (i.e., without working tree) under a blessed hierarchy,
like:
/repos/a.git
/repos/b.git
/repos/c.git

Once a few conventions have been established, it becomes trivial to
apply administrative operations (backup, packing, web publishing) to
the complete hierarchy, which serves a role not entirely dissimilar to
"monolithic" SVN repositories.  Working with these repositories also
becomes somewhat similar to SVN workflows, with the addition that one
can use local commits and branches:
svn checkout   --> git clone
svn update     --> git pull
svn commit     --> git push

You can have multiple remotes in each working clone, for the ease of
synchronizing between the multiple parties:
$ cd ~/dev
$ git clone /repos/foo.git       # or the one from github, ...
$ cd foo
$ git remote add github ...
$ git remote add memorystick ...

You can then fetch/pull from each of the "sources", work and commit
locally, and then push ("backup") to each of these remotes when you
are ready with something like (note how that pushes the same commits
and history to each of the remotes!):
$ for remote in origin github memorystick; do git push $remote; done

The easiest way to turn an existing working repository ~/dev/foo
into such a bare repository is probably:
$ cd ~/dev
$ git clone --bare foo /repos/foo.git
$ mv foo foo.old
$ git clone /repos/foo.git

which is mostly equivalent to a svn import--but does not throw the
existing, "local" history away.
Note: submodules are a mechanism to include shared related
lineages, so I indeed wouldn't consider them an appropriate tool for
the problem you are trying to solve.


[System] You are a helpful assistant.

[User] git-fetch - Download objects and refs from another repository  fetch.prune

[Assistant] If true, fetch will automatically behave as if the --prune option was given on the command line.  See also remote.<name>.prune and the PRUNING section of git-fetch .


[System] You are a helpful assistant.

[User]
Stash Git error "fatal: remote error: CAPTCHA required"
Attempting to pull from my Stash project, using the following commands:
$ git remote add origin https://[email protected]/scm/~username/project.git
$ git pull origin develop

I'm prompted for my password, which I enter and then get the following error:

Your Stash account has been marked as requiring a CAPTCHA to be solved before
  you may login again. This is typically caused by too many attempts to login
  with an incorrect password. The required CAPTCHA prevents your SCM client from
  accessing Stash until it is solved, even if you enter your password correctly.
  If you are currently logged in to Stash via a browser you may need to logout
  and then log back in in order to clear the CAPTCHA.

Logging out and back in again does not help. How do I fix this?

[Assistant] You might have a session to BitBucket open in a browser, that gives the impression that everything is fine. Simply logout and in again, when logging in you need to solve a CAPTCHA, after that you are good to go.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  guitool.<name>.noConsole

[Assistant]
Run the command silently, without creating a window to display its
output.


[System] You are a helpful assistant.

[User] git-stash - Stash the changes in a dirty working directory away  stash.showPatch

[Assistant]
If this is set to true, the git stash show command without an
option will show the stash entry in patch form.  Defaults to false.
See the description of the show command in git-stash .


[System] You are a helpful assistant.

[User]
git: How to delete a local ref branch?
I have bit of a difficulty in deleting a local ref branch(refs/notes/origin/commits).
I was able to delete the branch(refs/notes/origin/commits) in the remote repository using the command
git push origin :refs/notes/origin/commits

but when i try to delete the same branch on my local repository, i get the below error
[User@centos Clone]# git branch -rd refs/notes/origin/commits
error: remote branch 'refs/notes/origin/commits' not found.

Any suggestions?

[Assistant]
Just do
git branch -d commits

to delete the local branch.
Use the -D switch to delete it irrespective of its merged status.
Use
git update-ref -d refs/notes/origin/commits

to delete the ref.
You can also hard-delete it as mentioned in other answers with
rm -rf .git/refs/notes


[System] You are a helpful assistant.

[User] git-fsck - Verifies the connectivity and validity of the objects in the database  --root

[Assistant] Report root nodes.


[System] You are a helpful assistant.

[User]
Ignoring specific files, file types or folders in a pull request diff

We frequently use the Files Changed tab on a pull request to peer review the work we have done on a branch, unfortunately a major part of our development process is regenerating Flex services so when viewing the files changed 99% of the changes are irrelevant. This makes it very easy to miss important changes that should be reviewed.
We know the folder that these regenerated services live in, and we could commit all the regen changes in one commit if that would help.
Does anyone have any suggestions how we can improve this? Ideally we would exclude a folder from the pull request diff.

[Assistant]
Github supports this now with a .gitattributes file.

Create a .gitattributes file in the root of the repository.
Use the linguist-generated attribute to mark or unmark paths that you would like to be ignored for the repository's language statistics and hidden by default in diffs.

For example, to mark search/index.json as a generated file, add this line to .gitattributes:
search/index.json linguist-generated=true

Reference: https://help.github.com/en/github/administering-a-repository/customizing-how-changed-files-appear-on-github


[System] You are a helpful assistant.

[User]
Git pull results in extraneous "Merge branch" messages in commit log
I'm working with another developer on a project, and we're using Github as our remote repo. I'm on a Mac using git 1.7.7.3, he's on Windows using git 1.7.6.
This is what's happening

One of us (let's call him developer A, but it doesn't matter which one) pushes a set of commits to GitHub.
The other (developer B) makes some local commits.
B does a git pull.
B does a git push.
Looking at the commit history log, I see Merge branch 'master' of github.com:foo/bar

The commit log gets littered with "Merge branch" messages over time, and also shows developer B as committing changes that developer A made. The only way we've found to prevent this issue has been to do a git pull --rebase at step 3, but I don't know what side effects rebasing will introduce. This is my first time working on a multi-developer git repo, so is this just normal behavior? Any thoughts on how to solve this issue?

[Assistant]
The commit you are seeing is perfectly fine. A pull effectively runs git fetch and then git merge so a merge is usually happening when you run git pull.
The alternative to use rebasing instead of merging is possible, but usually you should avoid it. Rebasing allows you to keep a linear history, but also removes any information about the branching that originally happened. It will also cause the history of the current branch being rewritten, recreating all commits that are not contained in the target branch (in your case, the remote). As the recreated commits are different commits, this can cause a lot of confusion when developing together with others, especially when people already checked out parts of those commits before they get rewritten (for example with feature branches). So as a rule of thumb, you should never rewrite any commit that was already pushed.
The commits you see are there to combine two (or more) branches. It is perfectly fine to have a commit that does nothing else then merging multiple branches. In fact it makes it very clear when you have a merge commit that combines branches when looking at the history. In comparison to rebasing, merging also allows you to effectively see the original history as it was developed, including the actual branches that coexisted.
So, long story short: Yes, having merge commits is perfectly fine and you should not worry about them.


[System] You are a helpful assistant.

[User] git-blame - Show what revision and author last modified each line of a file  -p  --porcelain

[Assistant] Show in a format designed for machine consumption.


[System] You are a helpful assistant.

[User]
How can you git add a new file without staging it?
To use git effectively (and as intended) I make small atomic commits, while I do have longer sessions where I do change not only one thing. Thus, I make heavy use of git add -p. This doesn't work for completely new files, though, because I tend to forget them later on.
What I want to do is, tell git that there is a new file, I want it to track, but not stage it:
Example: Running git status produces:
# On branch my-current-branch
# Your branch is ahead of 'origin/my-current-branch' by 2 commits.
#
# Changes to be committed:
#
<<STAGED SECTION>> // A
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
<<UNSTAGED-YET-KNOWN SECTION>> // B
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
<<UNKNOWN SECTION>> // C

If I have a file foo in the C section, and I say git add foo it will go to the A section. If I say git add -N foo it will go to both A and B. However, that would mean it would be included in the next commit, at least as the fact that there is a new file.
I want it to go in section B exclusively, such that I can later add it to A with git add -p or git add foo (or whatever).
Edit
Regarding the add -N solution, this doesn't work because if I try to commit after having said add -N and not having added it properly, git complains because it doesn't know how to handle empty files:
foo: not added yet
error: Error building trees

[Assistant]
With Git 2.5, git add -N/--intent-to-add is actually the right solution.
The new file won't be part of the next commit.
See commit d95d728 by Nguyễn Thái Ngọc Duy (pclouds) (merged in d0c692263):

diff-lib.c: adjust position of i-t-a entries in diff

Problem:

Entries added by "git add -N" are reminder for the user so that they don't forget to add them before committing. These entries appear in the index even though they are not real. Their presence in the index leads to a confusing "git status" like this:

On branch master
Changes to be committed:
        new file:   foo

Changes not staged for commit:
        modified:   foo

If you do a "git commit", "foo" will not be included even though
  "status" reports it as "to be committed".

Solution:

This patch changes the output to become

On branch master
Changes not staged for commit:
        new file:   foo

no changes added to commit

That means:

Treat such paths as "yet to be added to the index but Git already know about them";
  "git diff HEAD" and "git diff --cached HEAD" should not talk about them, and "git diff" should show them as new.
  +   files yet to be added to the index.


[System] You are a helpful assistant.

[User] git-rev-list - Lists commit objects in reverse chronological order  --no-abbrev-commit

[Assistant]
Show the full 40-byte hexadecimal commit object name. This negates --abbrev-commit , either explicit or implied by other options such
as "--oneline". It also overrides the log.abbrevCommit variable.


[System] You are a helpful assistant.

[User]
GitLab Pages custom domain allow www

What do I need to do in order for my GitLab pages site (Jekyll) to be accessed under www.mydomain.com not just mydomain.com? I have SSL through CloudFlare.
In my DNS I have:
mydomain.com A 104.208.235.32
and CNAME points to myname.gitlab.io, and www points to myname.gitlab.io
Do I need to create a subdomain of www and point those to GitLab as well? I'd like my site to be without www in the url, but if a user types in www they should still be able to access the site.

[Assistant]
The configurations in the question are correct, what I didn't do is add both mydomain.com and www.mydomain.com as domains in GitLab (Settings icon > Pages > New Domain).
GitLab then directs traffic to both www and the naked domain when both domains are listed.


[System] You are a helpful assistant.

[User] git-tag - Create, list, delete or verify a tag object signed with GPG  -n<num>

[Assistant]
<num> specifies how many lines from the annotation, if any,
are printed when using -l. Implies --list . The default is not to print any annotation lines.
If no number is given to -n , only the first line is printed.
If the tag is not annotated, the commit message is displayed instead.


[System] You are a helpful assistant.

[User]
Share artifacts between workflows / Github Actions

I know that you can share artifacts between jobs of the same workflow...
But how can I share artifacts across different workflows?

[Assistant]
GitHub has now added a REST API for downloading artifacts. Basically you do
GET repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}

And then you'll have to look for Location: in the response, and then access that url to download the artifact. The url is valid for 1 minute.
There's a GitHub Action that uses the API above that you can easily add to your workflow. I use it like this
- name: Download artifact
  uses: dawidd6/action-download-artifact@v2
  with:
    workflow: ${{ github.event.workflow_run.workflow_id }}
    workflow_conclusion: success

Read more about it here: https://github.com/dawidd6/action-download-artifact


[System] You are a helpful assistant.

[User]
What does 'git remote add upstream' help achieve?

I was reading on:
https://wiki.diasporafoundation.org/Git_workflow#Rebase_your_development_branch_on_the_latest_upstream
Here is an extract:

Your Repository Up to Date
In order to get the latest updates from the development trunk do a
  one-time setup to establish the main GitHub repo as a remote by
  entering:
$ git remote add upstream git://github.com/diaspora/diaspora.git

Rebase Your Development Branch on the Latest Upstream
To keep your development branch up to date, rebase your changes on top
  of the current state of the upstream master. See the What’s
  git-rebase? section below to learn more about rebasing.
If you’ve set up an upstream branch as detailed above, and a
  development branch called 100-retweet-bugfix, you’d update upstream,
  update your local master, and rebase your branch from it like so:
$ git fetch upstream

$ git checkout master

$ git rebase upstream/master

$ git checkout 100-retweet-bugfix

[make sure all is committed as necessary in branch]
$ git rebase master

Why is adding a 'remote upstream' needed in this case? Coudn't I have just done:
$ git checkout master

$ git pull origin master

$ git checkout 100-retweet-bugfix

[make sure all is committed as necessary in branch]
$ git rebase master

[Assistant]
The wiki is talking from a forked repo point of view. You have access to pull and push from origin, which will be your fork of the main diaspora repo. To pull in changes from this main repo, you add a remote, "upstream" in your local repo, pointing to this original and pull from it.
So "origin" is a clone of your fork repo, from which you push and pull. "Upstream" is a name for the main repo, from where you pull and keep a clone of your fork updated, but you don't have push access to it.


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  lines

[Assistant]
Compute the dirstat numbers by doing the regular line-based diff
analysis, and summing the removed/added line counts. (For binary
files, count 64-byte chunks instead, since binary files have no
natural concept of lines). This is a more expensive --dirstat behavior than the changes behavior, but it does count rearranged
lines within a file as much as other changes. The resulting output
is consistent with what you get from the other --*stat options.


[System] You are a helpful assistant.

[User]
What is the meaning of revert this commit and roll back this commit in GitHub for Windows?

Github for Windows features these two commands described as:

revert this commit - create a new commit that reverts the changes of this commit
rollback this commit - roll back this commit leaving all changes made in this and later commits in your working directory

Could you explain the exact meaning of these two commands and how they can be used. Specifically I fail to understand what is the purpose of the second one. It makes no sense to me.
Is it possible to revert to a previous commit check it out and if I don't like it, go back to where it was initially?
This gui seems to feature a very small part of the git system but what would be a proper workflow utilizing it?

[Assistant]
Suppose you have a single file in your repo, and you have the following commits:
commit 1 : the file contains A
commit 2 : the file contains B
commit 3 : the file contains C

If you execute revert on commit 3, you'll have this in the repo:
commit 1 : the file contains A
commit 2 : the file contains B
commit 3 : the file contains C
commit 4 : the file contains B

And the file in your working copy will contain B as well.
If you execute roll back, you'll have this in the repo:
commit 1 : the file contains A
commit 2 : the file contains B

And the file in your working copy will be left unmodified. The file will thus contain C. It allows you to fix a small mistake and commit again, for example.


[System] You are a helpful assistant.

[User]
How can I reference an image in GitLab markdown in the current directory with the path starting with ./ dot slash?

I have stored a Markdown file and an image file in a Git repo as follows:

readme.markdown
images/

image.png

I reference the image from readme.markdown like this:
![](./images/image.png)

This renders as expected in ReText, but does not render when I push the repo to GitLab.
How can I reference the image from the Markdown file so that it renders when viewed in GitLab?

[Assistant]
![](images/image.png) without the ./ works for me: https://gitlab.com/cirosantilli/test/blob/bffbcc928282ede14dcb42768f10a7ef21a665f1/markdown.md#image
I have opened a request for this to be allowed at: http://feedback.gitlab.com/forums/176466-general/suggestions/6746307-support-markdown-image-path-in-current-directory-s , but it entered into Internet void when GitLab dumped UserVoice.


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  -z

[Assistant]
When --raw , --numstat , --name-only or --name-status has been
given, do not munge pathnames and use NULs as output field terminators. Without this option, pathnames with "unusual" characters are quoted as
explained for the configuration variable core.quotePath (see git-config ).


[System] You are a helpful assistant.

[User]
How can I stop .gitignore from appearing in the list of untracked files?
I just did a git init on the root of my new project.
Then I created a .gitignore file.
Now, when I type git status, .gitignore file appears in the list of untracked files. Why is that?

[Assistant]
The .gitignore file should be in your repository, so it should indeed be added and committed in, as git status suggests. It has to be a part of the repository tree, so that changes to it can be merged and so on.
So, add it to your repository, it should not be gitignored.
If you really want you can add .gitignore to the .gitignore file if you don't want it to be committed. However, in that case it's probably better to add the ignores to .git/info/exclude, a special checkout-local file that works just like .gitignore but does not show up in "git status" since it's in the .git folder.
See also https://help.github.com/articles/ignoring-files


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  origin

[Assistant]
The default upstream repository . Most projects have
at least one upstream project which they track. By default origin is used for that purpose. New upstream updates
will be fetched into remote-tracking branches named
origin/name-of-upstream-branch, which you can see using git branch -r .


[System] You are a helpful assistant.

[User] git - the stupid content tracker  gitformat-signature

[Assistant] Git cryptographic signature formats


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-format-patch

[Assistant] Prepare patches for e-mail submission


[System] You are a helpful assistant.

[User]
What's the difference between Git ignoring directory and directory/*?
I'm confused about what's the correct way to ignore the contents of a directory in git.
Assume I have the following directory structure:
my_project
     |--www
         |--1.txt
         |--2.txt
     |--.gitignore

What's the difference between putting this:
www

And this?
www/*

The reason I'm asking this question is: In git, if a directory is empty, git won't include such empty directory in repository. So I was trying the solution that is add an extra .gitkeep file under the directory so that it won't be empty. When I was trying that solution, if in the .gitignore file, I write like below:
www
!*.gitkeep

It doesn't work(My intention is to ignore all contents under www but keep the directory). But if I try the following:
www/*
!*.gitkeep

Then it works! So I think it must has some differences between the two approaches.

[Assistant]
There're differences among www, www/ and www/*.
Basically from the documentation and my own tests, www find a match with a file or a directory, www/ only matches a directory, while www/* matches directories and files inside www.
I'll only discuss on the differences between www/ and www/* here, since the differences between www and www/ are obvious.
For www/, git ignores the directory www itself, which means git won't even look inside. But for www/*, git checks all files/folders inside www, and ignores all of them with the pattern *. It seems to lead to the same results since git won't track an empty folder www if all its child files/folders are ignored. And indeed the results will be no difference for OP's case with www/ or www/* standalone. But it does make differences if it's combined with other rules.
For example, what if we want to only include www/1.txt but ignore all others inside www?
The following .gitignore won't work.
www/
!www/1.txt

While the following .gitignore works, why?
www/*
!www/1.txt

For the former, git just ignores the directory www, and won't even look inside to include www/1.txt again. The first rule excludes the parent directory www but not www/1.txt, and as a result www/1.txt cannot be "included again".
But for the latter, git first ignores all files/folers under www, and then includes one of them again which is www/1.txt.
For this example, the follwing lines in the documentation may help:

An optional prefix "!" which negates the pattern; any matching file
  excluded by a previous pattern will become included again. It is not
  possible to re-include a file if a parent directory of that file is
  excluded.


[System] You are a helpful assistant.

[User]
Recovering added/staged file after doing git reset --hard HEAD^?
I added a new file F1 and made changes to another file F2 but then did a git reset --hard HEAD^ and I have lost all the changes to the files.
Is there some way, I can get them back?
I did look at a related question here: How can I undo git reset --hard HEAD~1?  but, that question assumes that the one has done a Git commit.

[Assistant]
You can (with some work) recover state of file at the last "git add <file>". You can use
$ git fsck --cache --no-reflogs --lost-found --dangling HEAD

and then examine files in '.git/lost-found/other' directory.
Please read git fsck manpage.