[System] You are a helpful assistant.

[User]
How to set default remote in git?
I have multiple remotes in my git repository. If I execute git pull, then it asks for the password of one of my colleagues.
How can I change the remote to black?

[Assistant]
Edit: Thanks for all the upvotes!
In addition to the accepted answer to this question from @axiac that describes how to set the remote repository for an existing branch in your local copy, I felt it would be worthwhile to expand on this, by noting that while a default remote cannot be setup for git pull, a default remote can be set for git checkout in your repository using the checkout.defaultRemote setting.  This way, git checkout some-branch, git push, and git pull will all Just Work™ the way you intended, without specifying or thinking about the remote name at all. Read on for a full explanation.
Note to OP: In my examples below I'm going to use the remote name origin instead of your specific remote named black because for most people, the default origin remote is the one you'd want to setup like this.  For your purposes though, just replace any instance of origin with black.
Simplify your branch checkout process:
First, you'd type the following in the console:
git config checkout.defaultRemote origin

This command adds the following section to your repository's .git/config file:
[checkout]
     defaultRemote = origin

Now, with a default branch configured, each time you want to setup a new local copy of a remote branch that exists on the "origin" remote repository, you only need to type:
git checkout some-branch

And git will assume you actually meant:
git checkout --track origin/some-branch

Which can also be shortened to:
git checkout -u origin/some-branch

This is an amazing lifehack. It is a much smarter alternative method of setting up a local copy than the solution mentioned above with git checkout -b some-branch and is so very useful when you actually know that the branch already exists on one or more remotes.  Particularly, if you're working with multiple remotes and not using defaultRemote, you would need to type the long form git checkout --track origin/branch-name each time you checkout a branch, because git doesn't know from which remote it should track.  Save yourself a headache and just set this up always. (See final thoughts below for a suggested approach).
Simplify your git push and git pull process:
As hinted at above, having your local branches auto-configured to track from the defaultRemote means that when you need to do a git pull while on some branch you checked out, git already knows exactly which remote to pull from. This is very, very helpful.
Note: if the local branch tracks one remote and you want to pull code from a different remote, or if the local branch is not setup to track a remote at all, then you can either:

manually specify the correct remote to pull from:
  git pull <remote-name>

This must be done each time you want to pull from the remote.

fix the remote tracking branch permanently on a branch-by-branch basis using:
  git branch --set-upstream-to <remote-name/branch-name>

OR
  git config branch.<branch-name>.remote <remote-name>
  git config branch.<branch-name>.merge refs/heads/<branch-name>

This is a one-time change; all subsequent git pull commands should now pull from the remote/branch you specified.

Caveats and implications:
For git config checkout.defaultRemote origin to be of any real benefit for a git pull command scenario, this command/configuration needs to be set up when you first start working on a project with multiple remotes, or as soon as you start adding additional remotes. The reason is because this configuration will only have an effect on branches you're going to check out after having set this configuration; it doesn't have any effect on existing branches. In which case, all existing local branches that don't already track from a specific remote will need to be modified separately to add the intended remote before a simple git pull will work.
Final thoughts
If you find yourself hitting this issue often on various projects, a more comprehensive setting would be to work under the convention that the default remote should always be added as the "origin" remote in all your projects. You can then set this configuration globally with:
git config --global checkout.defaultRemote origin


[System] You are a helpful assistant.

[User]
When to use git subtree?
What problem does git subtree solve?
When and why should I use that feature?
I've read that it is used for repository separation. But why would I not just create two independent repositories instead of sticking two unrelated ones into one?
This GitHub tutorial explains how to perform Git subtree merges.
I kind of know how to use it, but not when (use cases) and why, and how it relates to git submodule. I'd use submodules when I have a dependency on another project or library.

[Assistant]
You should be careful to note explicitly what you are talking about when you use the term 'subtree' in the context of git as there are actually two separate but related topics here:
git-subtree and git subtree merge strategy.
The TL;DR
Both subtree related concepts effectively allow you to manage multiple repositories in one.  In contrast to git-submodule where only metadata is stored in the root repository, in the form of .gitmodules, and you must manage the external repositories separately.
More Details
git subtree merge strategy is basically the more manual method using the commands you referenced.
git-subtree is a wrapper shell script to facilitate a more natural syntax. This is actually still a part of contrib and not fully integrated into git with the usual man pages.  The documentation is instead stored along side the script.
Here is the usage info:
NAME
----
git-subtree - Merge subtrees together and split repository into subtrees

SYNOPSIS
--------
[verse]
'git subtree' add   -P <prefix> <commit>
'git subtree' add   -P <prefix> <repository> <ref>
'git subtree' pull  -P <prefix> <repository> <ref>
'git subtree' push  -P <prefix> <repository> <ref>
'git subtree' merge -P <prefix> <commit>
'git subtree' split -P <prefix> [OPTIONS] [<commit>]

I have come across a pretty good number of resources on the subject of subtrees, as I was planning on writing a blog post of my own.  I will update this post if I do, but for now here is some relevant information to the question at hand:
Much of what you are seeking can be found on this Atlassian blog by Nicola Paolucci the relevant section below:

Why use subtree instead of submodule?
There are several reasons why
  you might find subtree better to use:

Management of a simple workflow is easy.
Older version of git are supported (even before v1.5.2).
The sub-project’s code is available right after the clone of the super project is done.
subtree does not require users of your repository to learn anything new, they can ignore the fact that you are using subtree to manage dependencies.
subtree does not add new metadata files like submodules does (i.e.
  .gitmodule).
Contents of the module can be modified without having a
  separate repository copy of the dependency somewhere else.

In my opinion the drawbacks are acceptable:

You must learn about a new merge strategy (i.e. subtree).
Contributing code back upstream for the sub-projects is slightly more complicated.
The responsibility of not mixing super and sub-project code in commits lies with you.

I would agree with much of this as well.  I would recommend checking out the article as it goes over some common usage.
You may have noticed that he has also written a follow up here where he mentions an important detail that is left off with this approach...
git-subtree currently fails to include the remote!
This short sightedness is probably due to the fact that people often add a remote manually when dealing with subtrees, but this isn't stored in git either.  The author details a patch he has written to add this meta data to the commit that git-subtree already generates.  Until this makes it into the official git mainline you could do something similar by modifying the commit message or storing it in another commit.
I also find this blog post very informative as well.  The author adds a third subtree method he calls git-streeto the mix.  The article is worth a read as he does a pretty good job of comparing the three approaches. He gives his personal opinion of what he does and doesn't like and explains why he created the third approach.
Extras

listing git-subtrees
Detach Subdirectory

Closing Thoughts
This topic shows both the power of git and the segmentation that can occur when a feature just misses the mark.
I personally have built a distaste for git-submodule as I find it more confusing for contributors to understand. I also prefer to keep ALL of my dependencies managed within my projects to facilitate an easily reproducible environment without trying to manage multiple repositories. git-submodule, however, is much more well known currently so it is obviously good to be aware of it and depending on your audience that may sway your decision.


[System] You are a helpful assistant.

[User]
How do I reset the git master branch to the upstream branch in a forked repository?
I've completely messed up the master branch of my forked git repo.
I want to completely reset the master branch that was pushed to my fork with the contents of the upstream master repo.  I have no interest in retaining any master branch changes or history.
The simplest approach would have been to delete my forked repo and refork from the upstream project.  However, I have work in other pushed branches that I don't want to lose.
Thus how to I reset my pushed master branch with the upstream master?

git clone https://myrepo.git
cd myrepo
git remote add upstream https://upstream.git
git fetch upstream

Where do I go from here to reset my local and remote master branches with the upstream master?

[Assistant]
You can reset your local master branch to the upstream version and push it to your origin repository.
Assuming that "upstream" is the original repository and "origin" is your fork:
# ensures current branch is master
git checkout master

# pulls all new commits made to upstream/master
git pull upstream master

# this will delete all your local changes to master
git reset --hard upstream/master

# take care, this will delete all your changes on your forked master
git push origin master --force

(You can define the original repo as "upstream" with git remote add upstream /url/to/original/repo.)


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --show-pulls

[Assistant]
In addition to the commits shown in the default history, show
each merge commit that is not TREESAME to its first parent but
is TREESAME to a later parent. When a merge commit is included by --show-pulls , the merge is
treated as if it "pulled" the change from another branch. When using --show-pulls on this example (and no other options) the resulting
graph is: I---X---R---N Here, the merge commits R and N are included because they pulled
the commits X and R into the base branch, respectively. These
merges are the reason the commits A and B do not appear in the
default history. When --show-pulls is paired with --simplify-merges , the
graph includes all of the necessary information: .-A---M--.   N
	 /     /    \ /
	I     B      R
	 \   /      /
	  \ /      /
	   `---X--' Notice that since M is reachable from R , the edge from N to M was simplified away. However, N still appears in the history as an
important commit because it "pulled" the change R into the main
branch.


[System] You are a helpful assistant.

[User]
How to back up private branches in git
I have a local branch for day-to-day dev work in git. My workflow is:

Do stuff on local_branch, commit
Fetch origin/master
Rebase local_branch to catch up with new stuff from origin/master

It all works fine, however most of the recommendations I encountered say that one should not "push" private branches, on which rebase is regularly performed.
The problem here is that in this case local branch is not backed up to a server and the only way to save the work is to merge it back to "pushable" branch (i.e. origin/master)
What would be your recommendations on the workflow in this case?
Thanks!
UPDATE: I realised that one of the original requirements I had (avoiding usage of external utilities) is unnecessary limiting.
My current solution is to store all my repositories in a cloud-synchronised folder - this   way I get backup for free.

[Assistant]
I use the --mirror option and push to a personal backup repository:
Add it as a remote:
git remote add bak server:/path/to/backup/repo

Do the backup:
git push --mirror bak

This will automatically make your backup repository look like your active one -- branches will be created, deleted, updated (even forced/non-fastforwards) as needed.  You can make an alias for this too:
git config alias.bak "push --mirror bak"

Then, it's just a matter of running "git bak" when you want to do a backup.  You could also throw this into a cron job.


[System] You are a helpful assistant.

[User]
How to find a commit by its hash?
I need to find a commit in Git by a given hash, SHA. For example, if I have the "a2c25061" hash, and I need to get the author and the committer of this commit.
What is the command to get that?

[Assistant]
Just use the following command
git show a2c25061


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  porcelain

[Assistant]
Use a special line-based format intended for script
consumption.  Added/removed/unchanged runs are printed in the
usual unified diff format, starting with a + / - /` `
character at the beginning of the line and extending to the
end of the line.  Newlines in the input are represented by a
tilde ~ on a line of its own.


[System] You are a helpful assistant.

[User] git-add - Add file contents to the index

[Assistant]
DESCRIPTION This command updates the index using the current content found in
the working tree, to prepare the content staged for the next commit.
It typically adds the current content of existing paths as a whole,
but with some options it can also be used to add content with
only part of the changes made to the working tree files applied, or
remove paths that do not exist in the working tree anymore. The "index" holds a snapshot of the content of the working tree, and it
is this snapshot that is taken as the contents of the next commit.  Thus
after making any changes to the working tree, and before running
the commit command, you must use the add command to add any new or
modified files to the index. This command can be performed multiple times before a commit.  It only
adds the content of the specified file(s) at the time the add command is
run; if you want subsequent changes included in the next commit, then
you must run git add again to add the new content to the index. The git status command can be used to obtain a summary of which
files have changes that are staged for the next commit. The git add command will not add ignored files by default.  If any
ignored files were explicitly specified on the command line, git add will fail with a list of ignored files.  Ignored files reached by
directory recursion or filename globbing performed by Git (quote your
globs before the shell) will be silently ignored.  The git add command can
be used to add ignored files with the -f (force) option. Please see git-commit for alternative ways to add content to a
commit.


[System] You are a helpful assistant.

[User]
Viewing Git history of moved files
Despite reading lots of other posts regarding GIT and moved files I still struggle to understand how to trace the full history.  Doing gitk myfile as suggested here seems to only show history until the previous move.  I understand that GIT doesn't track files, only their content.  So surely I should be able to view the full evolution of a file, even if it's been moved?
Can anyone direct me to a good yet simple example/tutorial?
I'd like to see an example where some files are moved around, changed and committed, then the history of a single file is displayed, moves and all.  I've been looking at 'log' but that seems to concern checkins.  Would still appreciate some advice, even if its says I'm somehow still thinking too much SVN.

[Assistant]
Try using the --follow option to git log:
git log --follow file.txt


[System] You are a helpful assistant.

[User]
Can a deleted GitLab branch be restored?

There is a Git branch which was deleted by GitLab when closing a merge request.  I would like to restore (undelete) that branch; however, I'm not seeing an option in the UI to do so.
In GitHub it is possible to restore a branch deleted by a pull request after the fact (via the "Restore branch" button on the pull request).  I'm wondering if GitLab has an  analogous feature for closed merge requests.
I can of course do this manually through the Git command line, checking out the last commit hash for the deleted branch, and pushing it back up to the deleted branch name.  However, I would rather use the UI for something like this if it exists.
How can I restore a branch which GitLab deleted when closing a merge request?

[Assistant]
Restoring a deleted branch is an open issue, so GitLab has not implemented this feature at the time of this writing.
However, if you know the commit ID (and it hasn't been pruned), you can create a new branch from that commit:

From the Web UI, go to Repository > Commits
Find the commit you want and copy the SHA to your clipboard
Go to Repository > Branches
Click "New Branch"
Enter a branch name
Click the "Create from" drop-down menu and enter the commit SHA. Press enter to apply it.
Click "Create Branch"


[System] You are a helpful assistant.

[User]
What are these ^M's that keep showing up in my files in emacs?
I think it may have to do with TextMate, but we work in a small team and are having some issues with full-file conflicts of nearly identical files in git – in one branch the files have a ^M appended to each line.
What is this mysterious ^M character supposed to do, and where could it be coming from?
Our developers use emacs on Windows/Mac, TextMate on Mac, coda on Mac, and occasionally the wp-admin text editor.
Did anybody ever have this issue stemming from one of those?

[Assistant]
In git-config, set core.autocrlf to true to make git automatically convert line endings correctly for your platform, e.g. run this command for a global setting:
git config --global core.autocrlf true


[System] You are a helpful assistant.

[User] git - the stupid content tracker  --man-path

[Assistant]
Print the manpath (see man(1) ) for the man pages for
this version of Git and exit.


[System] You are a helpful assistant.

[User]
Installing non-public packages from Gitlab using devtools::install_git

My institution recently installed GitLab for us.  I've figured out how to install R packages from the GitLab server using devtools::install_git and it works as long as the project is public.
#* When modeltable project has Public status
devtools::install_git('https://mini-me2.lerner.ccf.org/nutterb/modeltable.git')

However, if I have a package that is listed as either "Internal" or "Private," I can't install the package without some form of authentication.  As of yet, I haven't figured out how to pass authentication via the URL.  Does anyone have experience with downloading packages from GitLab?
#* After changing the 'modeltable' project to Private status
devtools::install_git('https://mini-me2.lerner.ccf.org/nutterb/modeltable.git')
Preparing installation of modeltable using the Git-URL: https://mini-me2.lerner.ccf.org/nutterb/modeltable.git
'/usr/bin/git'clone --depth 1 --no-hardlinks https://mini-me2.lerner.ccf.org/nutterb/modeltable.git /tmp/Rtmp5aj1cU/file24493dc03a32
Error: There seems to be a problem retrieving this Git-URL.

[Assistant]
I'd highly recommend going the SSH route, and the below works for that.  I found making the leap to SSH was easy, especially with R and RStudio.  I'm using Windows in the below example.  Edits from code I use in practice are in all caps.
creds = git2r::cred_ssh_key("C:\\Users\\MYSELF\\.ssh\\id_rsa.pub",
                            "C:\\Users\\MYSELF\\.ssh\\id_rsa")
devtools::install_git("[email protected]:GITLABGROUP/PACKAGE.git",
                      credentials = creds)

Two quick additional comments:

git2r is imported with devtools, you shouldn't need to install it separately.
Also I don't think this should need mentioning, but passwords in plaintext in your script is a very bad idea.


[System] You are a helpful assistant.

[User]
Move branch to another branch
I have started doing some work on a branch which I have in term realised was the wrong branch. Is there a way to move a branch to a different branch.
For example:
A -- B -- C -- D -- HEAD
 \-- E -- F -- G -- H -- I -- J
      \-- K -- L

And I want this:
A -- B -- C -- D -- HEAD
 \    \-- K -- L
  \
   \-- E -- F -- G -- H -- I -- J

[Assistant]
Let's say you've named your branches like so:
    A -- B -- C -- D (master)
     \-- E -- G -- H -- I -- J (current-parent)
          \-- K -- L (my-branch)

What you want to do is rebase my-branch onto the B commit like so:
    git rebase current-parent my-branch --onto B


[System] You are a helpful assistant.

[User]
Gitlab Shell Script Permission Denied

I am running a simple shell script with Gitlab CICD and I am getting Permission denied. Kindly suggest
When I do chmod +x test.sh it says operation not permitted.
stages:
  - build

build:
  stage: build
  script:
    - ls
    - ./test.sh

Shell test.sh
echo Hi

Error:

[Assistant]
Instead of simply running chmod on your local system, it's better to run git update-index --chmod=+x path/to/file. This adds an executable flag to a file in Git and should ensure that a script can be executed inside a GitLab pipeline.
See also this question.


[System] You are a helpful assistant.

[User]
Is git's semi-secret empty tree object reliable, and why is there not a symbolic name for it?
Git has a well-known, or at least sort-of-well-known, empty tree whose SHA1 is:
4b825dc642cb6eb9a060e54bf8d69288fbee4904

(you can see this in any repo, even a newly created one, with git cat-file -t and git cat-file -p).  [Edit made in 2020: the SHA-256 empty tree hash ID is:
6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321

as VonC mentions in his answer.  My question was apparently about 8 years early. 😀]
If you work hard and are very careful you can sort of use this empty tree to store a directory that has no files (see answer to How do I add an empty directory to a git repository), although it's not really a great idea.
It's more useful as one argument to git diff-tree, which one of the sample hooks does.
What I'm wondering is,

how reliable is this—i.e., will some future version of git not have a git object numbered 4b825dc642cb6eb9a060e54bf8d69288fbee4904?
Why is there no symbolic name for the empty tree (or is there one?).

(A quick and dirty way to create a symbolic name is to put the SHA1 in, e.g., .git/Nulltree.  Unfortunately you have to do this for every repo.  Seems better to just put the magic number in scripts, etc.  I just have a general aversion to magic numbers.)

[Assistant]
This thread mentions:

If you don't remember the empty tree sha1, you can always derive it with:

git hash-object -t tree /dev/null

Or, as Ciro Santilli proposes in the comments:
printf '' | git hash-object --stdin -t tree

Or, as seen here, from Colin Schimmelfing:
git hash-object -t tree --stdin < /dev/null

So I guess it is safer to define a variable with the result of that command as your empty sha1 tree (instead of relying of a "well known value").
Note: Git 2.25.1 (Feb. 2020) proposes in commit 9c8a294:
empty_tree=$(git mktree </dev/null)

# Windows (Command Prompt):
git mktree <NUL

# Windows (PowerShell):
$null | git mktree

And adds:

As a historical note, the function now known as repo_read_object_file() was taught the empty tree in 346245a1bb ("hard-code the empty tree object", 2008-02-13, Git v1.5.5-rc0 -- merge), and the function now known as oid_object_info() was taught the empty tree in c4d9986f5f ("sha1_object_info: examine cached_object store too", 2011-02-07, Git  v1.7.4.1).

Note, you will see that SHA1 pop up on some GitHub repo when the author wants its first commit to be empty (see blog post "How I initialize my Git repositories"):
$ GIT_AUTHOR_DATE="Thu, 01 Jan 1970 00:00:00 +0000" GIT_COMMITTER_DATE="Thu, 01 Jan 1970 00:00:00 +0000" git commit --allow-empty -m 'Initial commit'

Will give you:

(See the tree SHA1?)
You can even rebase your existing history on top of that empty commit (see "git: how to insert a commit as the first, shifting all the others?")
In both cases, you don't rely on the exact SHA1 value of that empty tree.
You simply follow a best practice, initializing your repo with a first empty commit.

To do that:
git init my_new_repo
cd my_new_repo
git config user.name username
git config user.email email@com

git commit --allow-empty -m "initial empty commit"

That will generate a commit with a SHA1 specific to your repo, username, email, date of creation (meaning the SHA1 of the commit itself will be different every time).
But the tree referenced by that commit will be 4b825dc642cb6eb9a060e54bf8d69288fbee4904, the empty tree SHA1.
git log --pretty=raw

commit 9ed4ff9ac204f20f826ddacc3f85ef7186d6cc14
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904      <====
author VonC <[email protected]> 1381232247 +0200
committer VonC <[email protected]> 1381232247 +0200

    initial empty commit

To show just the tree of a commit (display the commit tree SHA1):
git show --pretty=format:%T 9ed4ff9ac204f20f826ddacc3f85ef7186d6cc14
4b825dc642cb6eb9a060e54bf8d69288fbee4904

If that commit, referencing an empty tree, is indeed your first commit, you can show that empty tree SHA1 with:
git log --pretty=format:%h --reverse | head -1 | xargs git show --pretty=format:%T
4b825dc642cb6eb9a060e54bf8d69288fbee4904

(and that even works on Windows, with Gnu On Windows commands)

As commented below, using git diff <commit> HEAD, this will show all your file in the current branch HEAD:
git diff --name-only 4b825dc642cb6eb9a060e54bf8d69288fbee4904 HEAD

Note: that empty tree value is formally defined in cache.h.
#define EMPTY_TREE_SHA1_HEX \
    "4b825dc642cb6eb9a060e54bf8d69288fbee4904"

Since Git 2.16 (Q1 2018), it is used in a structure which is no longer tied to  (only) SHA1, as seen in commit eb0ccfd:

Switch empty tree and blob lookups to use hash abstraction

Switch the uses of empty_tree_oid and empty_blob_oid to use the current_hash abstraction that represents the current hash algorithm in
use.

See more at "Why doesn't Git use more modern SHA?": it is SHA-2, since Git 2.19 (Q3 2018)

With Git 2.25 (Q1 2020), tests are preparing for a SHA-2 transition, and is involving the empty tree.
See commit fa26d5e, commit cf02be8, commit 38ee26b, commit 37ab8eb, commit 0370b35, commit 0253e12, commit 45e2ef2, commit 79b0edc, commit 840624f, commit 32a6707, commit 440bf91, commit 0b408ca, commit 2eabd38 (28 Oct 2019), and commit 1bcef51, commit ecde49b (05 Oct 2019) by brian m. carlson (bk2204).
(Merged by Junio C Hamano -- gitster -- in commit 28014c1, 10 Nov 2019)

t/oid-info: add empty tree and empty blob values
Signed-off-by: brian m. carlson

The testsuite will eventually learn how to run using an algorithm other than SHA-1. In preparation for this, teach the test_oid family of functions how to look up the empty blob and empty tree values so they can be used.

So t/oid-info/hash-info now includes:
rawsz sha1:20
rawsz sha256:32

hexsz sha1:40
hexsz sha256:64

zero sha1:0000000000000000000000000000000000000000
zero sha256:0000000000000000000000000000000000000000000000000000000000000000

algo sha1:sha1
algo sha256:sha256

empty_blob sha1:e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
empty_blob sha256:473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813

empty_tree sha1:4b825dc642cb6eb9a060e54bf8d69288fbee4904
empty_tree sha256:6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321

The SHA2 "6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321" is the new SHA1 "4b825dc642cb6eb9a060e54bf8d69288fbee4904" empty tree.


[System] You are a helpful assistant.

[User] git-pull - Fetch from and integrate with another repository or a local branch

[Assistant] SYNOPSIS git pull [<options>] [<repository> [<refspec>…]]


[System] You are a helpful assistant.

[User]
Gerrit error when Change-Id in commit messages are missing
I set up a branch in the remote repository and made some commits on that branch.
Now I want to merge the remote branch to the remote master.
Basically follows are my operations:

checkout branch
checkout master
merge branch and fix merging errors
commit
push origin HEAD:refs/for/master

But get error messages on the 5th step:
remote: Resolving deltas:   0% (0/12)

remote: ERROR: missing Change-Id in commit message
...

remote: Change-Id: I55862204ef71f69bc88c79fe2259f7cb8365699a

To ssh://[email protected]:29418/hello_git
 ! [remote rejected] HEAD -> refs/for/master (missing Change-Id in commit message)

[Assistant]
Check if your commits have Change-Id: ... in their descriptions. Every commit should have them.
If no, use git rebase -i to reword the commit messages and add proper Change-Ids (usually this is a SHA1 of the first version of the reviewed commit).
For the future, you should install commit hook, which automatically adds the required Change-Id.
Execute scp -p -P 29418 username@your_gerrit_address:hooks/commit-msg .git/hooks/ in the repository directory
or download them from
http://your_gerrit_address/tools/hooks/commit-msg and copy to .git/hooks
Now git commit --amend --no-edit inserts the line.


[System] You are a helpful assistant.

[User]
What are the advantages of keeping linear history in Git?
When I was taught using Git with central repo (project on Gitorious) I was told to always use rebase instead of merge because we want to have linear history. So, I have always been trying to work that way.
Now when I come to think about it is it really so beneficial? Rebasing branch with many commits is much more time consuming then simple merge.
There are 2 advantages that come to my mind right now:

git bisect
Possibility of submitting with history to another version control system like SVN.

Are there any other benefits?

[Assistant]
As far as I am concerned, keeping a linear history is mostly for asthetics. It's a very good way for a very skilled, disciplined developer to tidy up the history and make it nice to skim through. In a perfect world, we should have a perfectly linear history that makes everything crystal clear.
However, on a large team in an enterprise environment I often do not recommend artificially keeping a linear history. Keeping history linear on a team of sharp, experienced, and disciplined developers is a nice idea, but I often see this prescribed as a 'best practice' or some kind of 'must do'. I disagree with such notions, as the world is not perfect, and there are a lot of costs to keeping a linear history that people do not do a good job of disclosing. Here's the bullet list overview:

Rewriting history can include erasing history
Not everybody can even rebase
The benefits are often overstated

Now, let's dig into that. Warning: Long, anecdotal, mostly ranting
Rewriting history can include erasing history
Here's the problem with rebasing all of your commits to keep everything nice and linear: Rebasing is not generally loss-less. There is information- real, actual things that were done by the developer - that may be compressed out of your history when you rebase. Sometimes, that's a good thing. If a developer catches their own mistake, it's nice for them to do an interactive rebase to tidy that up. Caught-and-fixed mistakes have already been handled: we don't need a history of them. But some people work with that one individual who always seems to screw up merge conflicts. I don't personally know any developers named Neal, so let's say it's a guy named Neal. Neal is working on some really tricky accounts receivable code on a feature branch. The code Neal wrote on his branch is 100% correct and works exactly the way we want it to. Neal gets his code all ready to get merged into master, only to find there are merge conflicts now. If Neal merges master into his feature branch, we have a history of what his code originally was, plus what his code looked like after resolving the merge conflicts. If Neal does a rebase, we only have his code after the rebase. If Neal makes a mistake when resolving merge conflicts, it will be a lot easier to troubleshoot the the former than it will be the latter. But worse, if Neal screws up his rebase in a sufficiently unfortunate way (maybe he did a git checkout --ours, but he forgot he had important changes in that file), we could altogether lose portions of his code forever.
I get it, I get it. His unit tests should have caught the mistake. The code reviewer should have caught the mistake. QA should have caught the mistake. He shouldn't have messed up resolving the merge conflicts in the first place. Blah, blah, don't care. Neal is retired, the CFO is pissed because our ledger is all screwed up, and telling the CFO 'according to our development philosophy this shouldn't have happened' is going to get me punched in the face.
Not everybody can even rebase, bro. Yes, I've heard: You work at some space age startup, and your IoT coffee table uses only the coolest and most modern, reactive, block-chain based recurrent neural network, and the tech stack is sick! Your lead developer was literally there when Go was invented, and everybody who works there has been a Linux kernel contributor since they were 11. I'd love to hear more, but I just don't have time with how often I'm being asked 'How do I exit git diff???'. Every time someone tries to rebase to resolve their conflicts with master, I get asked 'why does it say my file is their file', or 'WHY DO I ONLY SEE PART OF MY CHANGE', and yet most developers can handle merging master into their branch without incident. Maybe that shouldn't be the case, but it is. When you have junior devs and interns, busy people, and people who didn't find out what source control is until they had already been a programmer for 35 years on your team, it takes a lot of work to keep the history pristine.
The benefits are often overstated.
We've all been on that one project where you do git log --graph --pretty and suddenly your terminal has been taken over by rainbow spaghetti. But history is not hard to read because it's non-linear...It's hard to read because it's sloppy. A sloppy linear history where every commit message is "." is not going to be easier to read than a relatively clean non-linear history with thoughtful commit messages. Having a non-linear history does not mean you have to have branches being merged back and forth with each other several times before reaching master. It does not mean that your branches have to live for 6 months. An occasional branch on your history graph is not the end of the world.
I also don't think doing a git bisect is that much more difficult with non-linear history. A skilled developer should be able to think of plenty of ways to get the job done. Here's one article I like with a decent example of one way to do it.
https://blog.smart.ly/2015/02/03/git-bisect-debugging-with-feature-branches/
tldr; I'm not saying rebases and linear history aren't great. I'm just saying you need to understand what you're signing up for and make an informed decision about whether or not it's right for your team. A perfectly linear history is not a necessity, and it certainly isn't free. It can definitely make life great in the right circumstances, but it will not make sense for everyone.


[System] You are a helpful assistant.

[User]
Git error no matching host key type found. Their offer: ssh-rsa
I get the following error when using git:
$ git pull
Unable to negotiate with 172.16.42.42 port 22: no matching host key type found. Their offer: ssh-rsa
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

How can I resolve this error?

[Assistant]
With SSH, there are several different types of keys and RSA keys (the ssh-rsa) kind can support multiple kinds of signatures.  The signature type ssh-rsa refers to RSA with SHA-1, whereas the signature type rsa-sha2-256 is RSA with SHA-256 and rsa-sha2-512 is RSA with SHA-512.
In the case of Azure DevOps, it only supports the kind of RSA with SHA-1, and SHA-1 is considered very weak.  This essentially means that there are no secure ways to connect to it over SSH, and until they fix that, you're better off using HTTPS or a different hosting service.  GitHub, GitLab, and Bitbucket all support secure methods of authentication.
If you really need to use SSH with Azure DevOps at the moment, you can add an entry to your ~/.ssh/config file to work around this:
Host ssh.dev.azure.com
    User git
    PubkeyAcceptedAlgorithms +ssh-rsa
    HostkeyAlgorithms +ssh-rsa

However, be aware that this is a workaround and it's known to be insecure, so you should contact Azure DevOps about this problem and switch to HTTPS until they do, or move elsewhere.


[System] You are a helpful assistant.

[User]
Git commit -a "untracked files"?
When I do a git commit -a, I am seeing the following:
  # Please enter the commit message for your changes. Lines starting
  # with '#' will be ignored, and an empty message aborts the commit.
  # On branch better_tag_show
  # Changes to be committed:
  #   (use "git reset HEAD <file>..." to unstage)
  #
  # modified:   ../assets/stylesheets/application.css
  # modified:   ../views/pages/home.html.erb
  # modified:   ../views/tags/show.html.erb
  # modified:   ../../db/seeds.rb
  #
  # Untracked files:
  #   (use "git add <file>..." to include in what will be committed)
  #
  # ../assets/stylesheets/
  # ../views/pages/

What does those untracked files mean? All the changes have been indeed tracked. I don't understand why git is warning me about untracked files here.
EDIT:
Ok I see a lot of confused replies. This is what happens after I git commit -a this.
# On branch master
nothing to commit (working directory clean)

As you can see, there is NOTHING other than those four files that had changes applied.
My question should be rephrased as follows: Why is git warning me about untracked files when all of the changes in this commit has been tracked?
In other words, is the untracked warning in the git commit message unnecessary?

[Assistant]
For others having the same problem, try running
git add .
which will add all files of the current directory to track (including untracked) and then use
git commit -a to commit all tracked files.
As suggested by @Pacerier, one liner that does the same thing is
git add -A


[System] You are a helpful assistant.

[User]
Getting permission denied (public key) on gitlab
My problem is that I can't push or fetch from GitLab. However, I can clone (via HTTP or via SSH). I get this error when I try to push :

Permission denied (publickey) fatal : Could not read from remote repository

From all the threads I've looked, here is what I have done :

Set up an SSH key on my computer and added the public key to GitLab
Done the config --global for username and email
Cloned via SSH and via HTTP to check if it would resolve the issue
Done the ssh -T [email protected] command

If you have any insight about how to resolve my issue, it would be greatly appreciated.

[Assistant]
I found this after searching a lot. It will work perfectly fine for me.

Go to "Git Bash" just like cmd. Right click and "Run as Administrator".
Type ssh-keygen
Press enter.
It will ask you to save the key to the specific directory.
Press enter. It will prompt you to type password or enter without password.
The public key will be created to the specific directory.
Now go to the directory and open .ssh folder.
You'll see a file id_rsa.pub. Open it on notepad. Copy all text from it.
Go to https://gitlab.com/-/profile/keys or
Paste here in the "key" textfield.
Now click on the "Title" below. It will automatically get filled.
Then click "Add key".

Now give it a shot and it will work for sure.


[System] You are a helpful assistant.

[User]
Mirror a git repository by pulling?
I am wondering if there is an easy way, ie like a simple cron job, to regularly pull from a remote git repository to a local read only mirror for backup purposes?
Ideally it would pull all branches and tags, but the master/trunk/head would be sufficient.
I just need a way to make sure that if the master git server dies, we have a backup location that we could manually fail over to.

[Assistant]
First create a mirror with
git clone --mirror [email protected]:repo.git

then setup a cron job like this:
*/1 * * * * gitbackup cd /backup/repo.git && git fetch -q --tags

This will backup the changesets every minute. Maybe you want to do this less frequently.


[System] You are a helpful assistant.

[User]
Stopping GitLab from skipping Git submodules during CI job?

I'm testing out deploying a Hexo site on GitLab Pages. I'm currently using a theme that someone has posted to GitHub, and thus have a Git submodule in the themes folder of my Hexo project such that the top-level .gitmodules file looks like:
[submodule "themes/Hacker"]
    path = themes/Hacker
    url = https://github.com/CodeDaraW/Hacker.git

I'm using the Hexo doc's recommended YAML file (updated for current Node) for CI settings, and the CI job seems to go smoothly except that it randomly decides to skip Git submodules setup:
Getting source from Git repository 00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/jjeffrey/jjeffrey.gitlab.io/.git/
Created fresh repository.
Checking out 76f8757a as master...
Skipping Git submodules setup
Restoring cache 00:01
Checking cache for default...
FATAL: file does not exist

This prevents the site from properly generating the HTML/CSS files because no theme is present:
$ hexo generate
INFO  Validating config
INFO  Start processing
INFO  Files loaded in 100 ms
WARN  No layout: 1970/01/01/hello-world/index.html
WARN  No layout: 1970/01/01/test_new/index.html
WARN  No layout: archives/index.html
WARN  No layout: archives/1970/index.html
WARN  No layout: archives/1970/01/index.html
WARN  No layout: index.html
INFO  Generated: archives/index.html
INFO  Generated: archives/1970/index.html
INFO  Generated: archives/1970/01/index.html
INFO  Generated: index.html
INFO  Generated: 1970/01/01/hello-world/index.html
INFO  Generated: 1970/01/01/test_new/index.html
INFO  6 files generated in 13 ms

How do I ensure that GitLab actually loads the Git submodule properly so that my theme loads?

[Assistant]
From gitlab documenation Using Git submodules with GitLab CI/CD:

Use Git submodules in CI/CD jobs
To make submodules work correctly in CI/CD jobs:

Make sure you use relative URLs for submodules located in the same GitLab server.

You can set the GIT_SUBMODULE_STRATEGY variable to either normal or recursive to tell the runner to fetch your submodules before the job:
variables:
     GIT_SUBMODULE_STRATEGY: recursive

Also see https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-submodule-strategy .


[System] You are a helpful assistant.

[User] git-log - Show commit logs  %GP

[Assistant]
show the fingerprint of the primary key whose subkey was used
to sign a signed commit


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  push

[Assistant]
Pushing a branch means to get the branch’s head ref from a remote repository ,
find out if it is an ancestor to the branch’s local
head ref, and in that case, putting all
objects, which are reachable from the local
head ref, and which are missing from the remote
repository, into the remote object database , and updating the remote
head ref. If the remote head is not an
ancestor to the local head, the push fails.


[System] You are a helpful assistant.

[User]
Remember GPG password when signing git commits
Would it be possible for the GPG password to be saved, so that I am not prompted for the passphrase everytime I make a git commit?

[Assistant]
You can set a timeout period for gpg-agent in ~/.gnupg/gpg-agent.conf with this line:
default-cache-ttl 3600

That would tell gpg-agent to store the passphrase for one hour.  You wouldn't want it to be indefinite, but not constantly typing it is of benefit too.


[System] You are a helpful assistant.

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

[Assistant]
This option controls whether git fetch (and the underlying fetch
in git pull ) will recursively fetch into populated submodules.
This option can be set either to a boolean value or to on-demand .
Setting it to a boolean changes the behavior of fetch and pull to
recurse unconditionally into submodules when set to true or to not
recurse at all when set to false. When set to on-demand , fetch and
pull will only recurse into a populated submodule when its
superproject retrieves a commit that updates the submodule’s
reference.
Defaults to on-demand , or to the value of submodule.recurse if set.


[System] You are a helpful assistant.

[User]
Large github commit diff not shown

This happens to me both with Compare view as well as standard commits that are large in the amount of files changed.
The screenshot below is from a compare between two branches with 380 files changed. The files at the beginning of the diff log have their diffs visualized but at a certain point down the page it stops visualizing the diffs. I understand you don't want massive pages but I can't seem to find a way to view a file's diff individually. Instead I have to check these both out locally and do the diff manually.
Does anyone have a simpler solution whether it be software driven or (preferably) a link i'm missing on github?

[Assistant]
Adding .patch to the end of the URL somewhat helps. Removes the nice UI and comment functionality, of course.
An example. If your pull request is: https://github.com/JustinTulloss/zeromq.node/pull/47, then the patch can be found at https://github.com/JustinTulloss/zeromq.node/pull/47.patch


[System] You are a helpful assistant.

[User]
Rebasing in smartgit "git-am is in progress"
I will try to explain the problem that I have. I have used the rebase option via git bash many times. Now I have SmartGit and don’t know why rebase is not correct.
Step 1:

Step 2:

Step 3:

The result is that HEAD detaches.

[Assistant]
The same issue i have faced, i will delete the local branch in my machine and recreate it from origin each and every time. But finally i got the solution. I ran the below command
git am --abort solved my problem.


[System] You are a helpful assistant.

[User]
"Git fatal: ref HEAD is not a symbolic ref" while using maven release plugin
I get the following error output while running the Maven release plugin prepare step i.e. mvn release:prepare --batch-mode -DreleaseVersion=1.1.2 -DdevelopmentVersion=1.2.0-SNAPSHOT -Dtag=v1.1.2 -X from an Atlassian Bamboo plan. However doing the same in the command line works fine. The full error stack is below.
Any ideas how can this be solved?
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project hpcmom: An error is occurred in the checkin process: Exception while executing SCM command. Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4.2:prepare (default-cli) on project hpcmom: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.plugins.release.PrepareReleaseMojo.prepareRelease(PrepareReleaseMojo.java:281)
    at org.apache.maven.plugins.release.PrepareReleaseMojo.execute(PrepareReleaseMojo.java:232)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: org.apache.maven.shared.release.ReleaseExecutionException: An error is occurred in the checkin process: Exception while executing SCM command.
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.checkin(AbstractScmCommitPhase.java:160)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.performCheckins(AbstractScmCommitPhase.java:145)
    at org.apache.maven.shared.release.phase.ScmCommitPreparationPhase.runLogic(ScmCommitPreparationPhase.java:76)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.execute(AbstractScmCommitPhase.java:78)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:234)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:169)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:146)
    at org.apache.maven.shared.release.DefaultReleaseManager.prepare(DefaultReleaseManager.java:107)
    at org.apache.maven.plugins.release.PrepareReleaseMojo.prepareRelease(PrepareReleaseMojo.java:277)
    ... 22 more
Caused by: org.apache.maven.scm.ScmException: Exception while executing SCM command.
    at org.apache.maven.scm.command.AbstractCommand.execute(AbstractCommand.java:63)
    at org.apache.maven.scm.provider.git.AbstractGitScmProvider.executeCommand(AbstractGitScmProvider.java:291)
    at org.apache.maven.scm.provider.git.AbstractGitScmProvider.checkin(AbstractGitScmProvider.java:217)
    at org.apache.maven.scm.provider.AbstractScmProvider.checkIn(AbstractScmProvider.java:410)
    at org.apache.maven.shared.release.phase.AbstractScmCommitPhase.checkin(AbstractScmCommitPhase.java:156)
    ... 30 more
Caused by: org.apache.maven.scm.ScmException: Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref

    at org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand.getCurrentBranch(GitBranchCommand.java:147)
    at org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand.createPushCommandLine(GitCheckInCommand.java:192)
    at org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand.executeCheckInCommand(GitCheckInCommand.java:132)
    at org.apache.maven.scm.command.checkin.AbstractCheckInCommand.executeCommand(AbstractCheckInCommand.java:54)
    at org.apache.maven.scm.command.AbstractCommand.execute(AbstractCommand.java:59)
    ... 34 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
simple  02-Dec-2013 17:18:09    Failing task since return code of [/opt/dev/apache-maven/3.0.5//bin/mvn -Djava.io.tmpdir=/opt/atlassian/bamboo/5.2.1/temp/HPCMOM-RELEASE-JOB1 release:prepare --batch-mode -DignoreSnapshots=false -DreleaseVersion=1.1.2 -DdevelopmentVersion=1.2.0-SNAPSHOT -Dtag=v1.1.2 -X] was 1 while expected 0

UPDATE:
Doing git ls-remote . on a local workspace clone produces:
azg@olympus:~/code/hpcmom$ git ls-remote .
7894eea08a0afecb99515d1339623be63a7539d4    HEAD
7894eea08a0afecb99515d1339623be63a7539d4    refs/heads/master
7894eea08a0afecb99515d1339623be63a7539d4    refs/remotes/origin/HEAD
7894eea08a0afecb99515d1339623be63a7539d4    refs/remotes/origin/master
6a7095b86cccdfd4b28e4dea633d0930809ae9ac    refs/tags/v1.0
1a53462b1ecf0abfea8245016304cda9c78b420d    refs/tags/v1.0^{}
5113a7cbcf35c47b680a9c36e15e5fa01ef1d2e6    refs/tags/v1.1
79a3073ecabe65d3c8051520f8007d9e49a65a06    refs/tags/v1.1^{}
a00249209597ea1214d80ee38f228c40db7022c2    refs/tags/v1.1.0
e892bce8d25d87368ab557fee0d30810bef7e31e    refs/tags/v1.1.0^{}
b491a312c39088533cb069e4ab1ae8a00d1f6bfe    refs/tags/v1.1.2
a3f7618dada7ed60d8190426152ffd90e0e40a86    refs/tags/v1.1.2^{}

Doing git ls-remote . on the Bamboo clone produces:
azg@olympus:/var/atlassian/application-data/bamboo/xml-data/build-dir/HPCMOM-RELEASE-JOB1$ git ls-remote .
2422ce066ac35dae3c54f1435ef8dae5008a9a14    HEAD
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/heads/master
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/remotes/origin/HEAD
57c08d581c0fd9e788049733fbdc9c22b9a6ae00    refs/remotes/origin/master
7539f9700d78a1b766fca7ed9f409914f1ea9d08    refs/tags/vnull
6bfa8c3fdb1f8f56a385035f01b1b77b6e88da8b    refs/tags/vnull^{}

and this is very weird why is the local development clone output so different from the Bamboo one?

[Assistant]
I ran into the same error on Jenkins in combination with maven release plugin, we fixed it by going to Additional behaviours, Check out to specific local branch and enter 'master'
I realise this is not a solution but it might give you some direction in where to look.


[System] You are a helpful assistant.

[User]
How to automate git merge to not prompt to confirm the commit message?
I'm trying to do some automation scripts using git, simple things like updating submodules, moving to proper tags etc, but one of the problems I'm now finding is that git now forces you to confirm a merge message. Is there any way to squelch this behavior from happening?

[Assistant] You can add the --no-edit switch to git-merge and it will not ask you to confirm the merge message.


[System] You are a helpful assistant.

[User]
How do I check the date and time of the latest `git pull` that was executed?
How do I check the date and time of the latest git pull that was executed? I frequently need to know when the code changed on a server when something goes wrong.

[Assistant]
stat -c %Y .git/FETCH_HEAD

Will give you a unix timestamp of the last modification of that file.
Git writes the FETCH_HEAD file every time you pull or fetch, even if there was nothing to pull.


[System] You are a helpful assistant.

[User]
Removing contributor from github.com?
How to remove contributor from showing in the main page of project:

Link https://help.github.com/articles/removing-a-collaborator-from-a-personal-repository/ says it possible in settings, but I dont see any collaborator in there:

[Assistant]
The below method works in my case at least.

In the GitHub web interface, change a branch name (From main to main1 for example). You can do that from the url https://github.com/[user]/[repo]/branches. It will update the contributor list on the repository dashboard.

Then change the name back (main1 to main).

I have multiple GitHub accounts for different projects and different communities and I accidentally pushed a commit using a wrong account. I changed the author of the commit, but the wrong account was still on the contributors list in the repository dashboard.
My method keeps the commit history as well as the GitHub action settings and issue history. But I did not check if pull requests are kept.


[System] You are a helpful assistant.

[User]
Why is Jenkins failing when fetching from git, while the command line isn't?
All of my Jenkins builds are failing at the git fetch line.
It's failing at git fetch --tags --progress [email protected]:ethenwilson/whentoact.git
Started by user anonymous
Building in workspace /Users/ethen/.jenkins/workspace/Build NikNik
 > git rev-parse --is-inside-work-tree
Fetching changes from the remote Git repository
 > git config remote.origin.url [email protected]:ethenwilson/whentoact.git
Fetching upstream changes from [email protected]:ethenwilson/whentoact.git
 > git --version
using GIT_SSH to set credentials NikNik BitBucket SSH Key
 > git fetch --tags --progress [email protected]:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*
FATAL: Failed to fetch from [email protected]:ethenwilson/whentoact.git
hudson.plugins.git.GitException: Failed to fetch from [email protected]:ethenwilson/whentoact.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:622)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:854)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:879)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1252)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:624)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:530)
    at hudson.model.Run.execute(Run.java:1732)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:234)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress [email protected]:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: remote: Counting objects: 2682, done.[K
remote: Compressing objects:   0% (1/1399)   [K
remote: Compressing objects:   1% (14/1399)   [K
...
remote: Compressing objects:  99% (1398/1399)   [K
remote: Compressing objects: 100% (1399/1399)   [K
remote: Compressing objects: 100% (1399/1399), done.[K
Receiving objects:   0% (1/2682)
Receiving objects:   1% (27/2682)
...
Receiving objects:  78% (2092/2682), 4.07 MiB | 1.59 MiB/s
Corrupted MAC on input.
Disconnecting: Packet corrupt
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1325)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1186)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:257)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:620)
    ... 10 more

When I run git fetch --tags --progress [email protected]:ethenwilson/whentoact.git from the command line, it works fine, which means my SSH keys must be working.
I'm connecting to BitBucket with Jenkins with SSH verification. Jenkins gets the key from the file it's located (the default one), so I know that Jenkins is using the same key as I am when I run from the command line.
I'm using the latest build of the BitBucket and Git plugins for Jenkins. My installed Git on my Mac is version 1.8.5.2 (Apple Git-48).
My jenkins start command is nohup java -jar ~/jenkins.war --httpPort=8081 --ajp13Port=8010 > /tmp/jenkins.log 2>&1 &.
What's going wrong?
EDIT: I was wrong, I had accidentally hit an option to have the SSH Key be in the wrong place when I did that. Now, using @borrrden's suggestion, it still gives the same error. **EDIT: As @borrrden suggested, I changed my start command to nohup java -Dorg.jenkinsci.plugins.gitclient.Git.useCLI=true -jar ~/Downloads/jenkins.war --httpPort=8081 --ajp13Port=8010 > /tmp/jenkins.log 2>&1 &, and now I get a different crash:
Started by user anonymous
Building in workspace /Users/ethen/.jenkins/workspace/Build NikNik
 > git rev-parse --is-inside-work-tree
Fetching changes from the remote Git repository
 > git config remote.origin.url [email protected]:ethenwilson/whentoact.git
Fetching upstream changes from [email protected]:ethenwilson/whentoact.git
 > git --version
using GIT_SSH to set credentials NikNik BitBucket SSH Key
 > git fetch --tags --progress [email protected]:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*
FATAL: Failed to fetch from [email protected]:ethenwilson/whentoact.git
hudson.plugins.git.GitException: Failed to fetch from [email protected]:ethenwilson/whentoact.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:622)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:854)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:879)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1252)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:624)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:530)
    at hudson.model.Run.execute(Run.java:1732)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:234)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress [email protected]:ethenwilson/whentoact.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1406)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1194)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:265)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:620)
    ... 10 more

[Assistant]
1) Go to job configuration
2) Go to the "Source Code Management" section
3) Additional behaviors > add
4) Select "Wipe out repository and force clone"
This will delete and re-clone only the workspace which is for your job. If you'd like to confirm before deleting, then I suggest echoing out the $WORKSPACE variable via a batch/bash command build step.
Also, this makes the build much slower, so I suggest removing it after one build.


[System] You are a helpful assistant.

[User]
Git show all branches (but not stashes) in log
I have a Git alias that expands to:
git log --graph --oneline --all --decorate

According to man git log there are a couple of suspicious options: --not and --branches; but I can't make it work properly.
How should I edit that to hide the stashes?

FYI: as per the accepted question and comment my .gitconfig alias now looks like this:
[alias]
    l = log --branches --remotes --tags --graph --oneline --decorate --notes HEAD

[Assistant]
Instead of doing --all and then trying to filter out the stashes, don't ever include them in the first place:
git log --branches --remotes --tags --graph --oneline --decorate

The main problem that arises from trying to filter them out afterwards is that if the stash is the latest commit on that branch (because even though it's not the head of the branch, it's still the most recent descendant of it), it can actually filter out the entire branch from the log, which isn't what you want.


[System] You are a helpful assistant.

[User]
Is there a way to use wildcards with git checkout?
What I would like to do is to checkout a single file or a set of files with a common name part like this
git checkout myBranch */myFile.md and
git checkout myBranch -- */*Test* (not sure about the '--' part)
instead of
git checkout myBranch src/main/java/a/deep/package/structure/myFile.md and
git checkout myBranch src/test/java/a/deep/package/structure/TestOne.java
git checkout myBranch src/test/java/a/deep/package/structure/TestTwo.java
git checkout myBranch src/test/java/a/deep/package/structure/resources/TestData.sql
I know there is some limited wildcard functionality for some git command like diff and add but have found nothing for checkout. Is there a way?
EDIT: I am using git 1.7.9.5 on Linux. A working combination of git and shell commmands would be acceptable as well.

[Assistant]
Git does deal with wildcards, using fnmatch(3). See the pathspec entry in Git glossary.
But to be sure that git can see the wildcards, they must be escaped otherwise your shell will expand them first. Typically, I use wildcards between single-quotes:
git checkout myBranch -- '*/myFile.md'

The wildcards are applied to the whole name, directories included.
As you can see in the documentation, the pathspec also allows magic signature which change how to interpret the pathspec. For example, you can have case-insensitive paths with icase (you can type ':(icase)*readme*' to find all your readme's).
I quote @bambams's comment here, in case you have problems in Windows:

This is not working for me in Windows with 2.8.1.windows.1 and I'm
  utilizing Git from the cmd.exe shell so no globbing built in. There is
  however a solution if you're in such a sorry state. Combine git diff --name-only and xargs to achieve your goal:
git diff --name-only <COMMIT> -- <GLOB>... | xargs git checkout <COMMIT>


[System] You are a helpful assistant.

[User]
Is it dangerous to keep code in gitlab and github

Is it dangerous to keep code in gitlab and github?
I heard it is quite safe to commit our code to gitlab and github.
The reason is every code is hashed and it is nearly impossible for everyone to alter the code without using git tool.
Is this true?

[Assistant]
As I mentioned in "Why does Git use a cryptographic hash function?", it is "safe" in term of data integrity (Linus Torvalds, 2007):

We check checksums that is considered cryptographically secure. Nobody has been able to break SHA-1, but the point is, SHA-1 as far as git is concerned, isn't even a security feature. It's purely a consistency check.
  The security parts are elsewhere.
  A lot of people assume since git uses SHA-1 and SHA-1 is used for cryptographically secure stuff, they think that it's a huge security feature. It has nothing at all to do with security, it's just the best hash you can get.
Having a good hash is good for being able to trust your data

This has nothing to do with:

privacy (which doesn't depend on Git itself, but on the Git hosting server, like gitHub or BitBucket)
user identity (to really be sure about a commit user, as Thilo comments, you can sign commits (see "A Git Horror Story: Repository Integrity With Signed Commits")

The OP add:

what I mean is the owner of gitlab or github may steal our code

This is a question of trust: Does the git hosting server have access to your code if it is in a private repo? Technically yes.
Will they access your private code? As mentioned in "Can third party hosts be trusted for closed-source/private source code management?", nothing prevents them to.
Yet, many startups have their private code on, for instance, GitHub.
If you have real confidentiality concern, then it is important you keep the ownership of the all codebase, including the server where it is stored (meaning having your own Git repo hosting server).


[System] You are a helpful assistant.

[User]
Git how to checkout a commit of a branch
How can I check out a commit version of a branch in git?
For example, my branch, Dev, has a commit ad4f43af43e. How can I check out that commit? Not just a single file, but a whole branch.
I searched online and found: git checkout <commit>, but it didn't specify branch name

[Assistant]
git checkout <hash>         # non named commit
git checkout <branch_name>  # named commit

The two lines above will place the HEAD pointer on the given commit. You should know that a branch name is a commit, except it can evolve if a new commit is added when you're on that branch.
If you want to place your branch Dev on the commit ad4f43af43e you can do this
git branch -f Dev ad4f43af43e

Be careful! This is dangerous because you may lose commits.


[System] You are a helpful assistant.

[User]
How to skip GitHub Actions job on push event?

With Travis CI, we can skip the build for a particular commit with adding a suffix to a commit. This is described at Travis CI. I find this feature practical when I only edit README.md which is not code-related and the pre-flight build doesn't need to be triggered.
[skip ci]

How do I skip the jobs trigged on: push events using GitHub Actions?
name: Maven Build
on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Check-out project
      uses: actions/checkout@v1
    - name: Set up JDK 11.0.3
      uses: actions/setup-java@v1
      with:
        java-version: 11.0.3
    - name: Build with Maven
      run: mvn -B package --file pom.xml

Answers summary:
Big thanks to all the answerers providing various ways to achieve it. I bet everybody would need something a little bit different regarding to the origin of their problem and the CI approach. Here are the answers listed for a quick navigation:

Skip CI on readme.md file: https://stackoverflow.com/a/61876395/3764965
Skip CI on [skip ci] as a new GitHub feature:

https://stackoverflow.com/a/66156840/3764965 (answer here)
https://stackoverflow.com/a/66114678/3764965 (answer in another question)

Skip CI on [skip ci] message by parsing (customizable solution):

https://stackoverflow.com/a/59775665/3764965

Allow CI per specific branch: https://stackoverflow.com/a/61876395/3764965

All the answers deserve upvote! If you like my question, you should double-like the answers.

[Assistant]
UPDATE: Please see Helmisek anwser, which points out that Github has the functionality built-in now.
My answer only makes sense, if you want to skip just some jobs/steps.

You can give the following a try:
name: Maven Build
on: [push]

jobs:
  build:
    if: "!contains(github.event.commits[0].message, '[skip ci]')"
    runs-on: ubuntu-latest

    steps:
    - name: Check-out project
      uses: actions/checkout@v1
    - name: Set up JDK 11.0.3
      uses: actions/setup-java@v1
      with:
        java-version: 11.0.3
    - name: Build with Maven
      run: mvn -B package --file pom.xml


[System] You are a helpful assistant.

[User]
AWS-CDK and Gitlab returns Error: spawnSync docker ENOENT

I am trying to run a Gitlab pipeline that builds an AWS-CDK project via the cdk-synth command. I have followed advice online in terms of what images I should be using in the Gitlab runner but I am running into the following error:

Error: spawnSync docker ENOENT

I'm not sure what this error means exactly, I guess it is trying to launch docker (which is used by thecdk synth command) but failing to do so. Again what I have found online all suggests to use the setup I currently have which is:
image: node:16.3.0-alpine

stages:
  - build
  - test
  - .post

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm
    - node_modules

build:
  tags:
    - mytag
  environment: ${CI_COMMIT_BRANCH}
  stage: build
  script:
    - npm i
    - cdk synth --no-staging > template.yaml
  artifacts:
    paths:
      - cdk.out
    expire_in: 30 mins

I'm really lost with this one, it may be staring me right in the face but could someone please point me in the right direction as to why i'd be getting this error when the image i'm using is itself a docker container?

[Assistant] I was stuck on this as well, but was able to get around it by adding esbuild as to my devDependencies in package.json.


[System] You are a helpful assistant.

[User]
Git error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied
I am having a strange issue that I can't seem to resolve. Here is what happend:
I had some log files in a github repository that I didn't want there. I found this script that removes files completely from git history like so:
    #!/bin/bash
set -o errexit

# Author: David Underhill
# Script to permanently delete files/folders from your git repository.  To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2

if [ $# -eq 0 ]; then
    exit 0are still
fi

# make sure we're at the root of git repo
if [ ! -d .git ]; then
    echo "Error: must run this script from the root of a git repository"
    exit 1
fi

# remove all paths passed as arguments from the history of the repo
files=$@
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD

# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune

I, of course, made a backup first and then tried it. It seemed to work fine. I then did a git push -f and was greeted with the following messages:
error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied
error: Cannot update the ref 'refs/remotes/origin/master'.

Everything seems to have pushed fine though, because the files seem to be gone from the GitHub repository, if I try and push again I get the same thing:
error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied
error: Cannot update the ref 'refs/remotes/origin/master'.
Everything up-to-date

EDIT
$ sudo chgrp {user} .git/logs/refs/remotes/origin/master
$ sudo chown {user} .git/logs/refs/remotes/origin/master
$ git push
Everything up-to-date

Thanks!
EDIT
Uh Oh. Problem. I've been working on this project all night and just went to commit my changes:
error: Unable to append to .git/logs/refs/heads/master: Permission denied
fatal: cannot update HEAD ref

So I:
sudo chown {user} .git/logs/refs/heads/master
sudo chgrp {user} .git/logs/refs/heads/master

I try the commit again and I get:
error: Unable to append to .git/logs/HEAD: Permission denied
fatal: cannot update HEAD ref

So I:
sudo chown {user} .git/logs/HEAD
sudo chgrp {user} .git/logs/HEAD

And then I try the commit again:
16 files changed, 499 insertions(+), 284 deletions(-)
create mode 100644 logs/DBerrors.xsl
delete mode 100644 logs/emptyPHPerrors.php
create mode 100644 logs/trimXMLerrors.php
rewrite public/codeCore/Classes/php/DatabaseConnection.php (77%)
create mode 100644 public/codeSite/php/init.php
$ git push
Counting objects: 49, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 7.72 KiB, done.
Total 27 (delta 15), reused 0 (delta 0)
To [email protected]:IAmCorbin/MooKit.git
59da24e..68b6397  master -> master

Hooray. I jump on http://GitHub.com and check out the repository, and my latest commit is no where to be found. ::scratch head:: So I push again:
Everything up-to-date

Umm...it doesn't look like it. I've never had this issue before, could this be a problem with github? or did I mess something up with my git project?
EDIT
Nevermind, I did a simple:
git push origin master

and it pushed fine.

[Assistant]
This looks like you ran git as root locally, thus changing ownership on some of the files tracking the location of the origin branch.
Fix the file ownership, and you should be fine:
# run this from the root of the git working tree
sudo chown -R "${USER:-$(id -un)}" .


[System] You are a helpful assistant.

[User]
How to undelete a branch on github?

It seems that I delete a branch on github when I should not do it.
What I did was as follow:
1- I add a new .gitignore to my system
2- I use
 git rm -r --cached .
 git add .
 git commit -m ".gitignore is now working"

When I did this, I had one branch on my local system but the server had two branch.
Then I pushed my branches to server and since I had not the second branch, the second branch was deleted on server.
How can I bring it back?
I am using Github as remote server.

[Assistant]
If you know the last commit message of the deleted branch you can do this:
git reflog

# search for message
fd0e4da HEAD@{14}: commit: This is the commit message I want

# checkout revision
git checkout fd0e4da

or
git checkout HEAD@{14}

# create branch
git branch my-recovered-branch

# push branch
git push origin my-recovered-branch:my-recovered-branch


[System] You are a helpful assistant.

[User]
Use Gitlab's CI/CD with submodules - cannot run ssh

I have a two private repositories: MyProject, MyProjetUtils.
My project uses the MyProjectUtils as a submodule.
My .gitsubmodules looks like this:
[submodule "MyProjetUtils"]
    path = MyProjetUtils
    url = [email protected]:MyCompany/MyProjetUtils.git

My .gitlab-ci.yml file looks like this:
default:
  image: python:latest
variables:
  GIT_SUBMODULE_STRATEGY: recursive
all_test:
  stage: test
  script:
    - apt-get update
    - pip install -r requirements.txt
    - python tests/run_tests.py

The error I'm getting during the job run:
Updating/initializing submodules recursively with git depth set to 50...
Submodule 'MyProjetUtils' ([email protected]:MyCompany/MyProjetUtils.git) registered for path 'MyProjetUtils'
Cloning into '/builds/MyCompany/MyProject/MyProjetUtils'...
error: cannot run ssh: No such file or directory
fatal: unable to fork
fatal: clone of '[email protected]:MyCompany/MyProjetUtils.git' into submodule path '/builds/MyCompany/MyProject/MyProjetUtils' failed
Failed to clone 'MyProjetUtils'. Retry scheduled

This error occur before the test stage. I've looked for answer here, and here but could not find an answer.

[Assistant]
The first link you posted has the solution you are looking for:

When your submodule is on the same GitLab server, you should use relative URLs in your .gitmodules file. Then you can clone with HTTPS in all your CI/CD jobs. You can also use SSH for all your local checkouts.

Assuming that your submodules are in the same group, update your .gitmodules to use a relative URL.
ie:
[submodule "MyProjetUtils"]
    path = MyProjetUtils
    url = ../../MyCompany/MyProjetUtils.git

May need to update ../../ to work for your groups.


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  %gN

[Assistant] reflog identity name (respecting .mailmap, see git-shortlog or git-blame )


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  unmerged index

[Assistant] An index which contains unmerged index entries .


[System] You are a helpful assistant.

[User]
git apply fails with "patch does not apply" error
I have a certain patch called my_pcc_branch.patch.
When I try to apply it, I get following message:
$ git apply --check my_pcc_branch.patch
warning: src/main/java/.../AbstractedPanel.java has type 100644, expected 100755
error: patch failed: src/main/java/.../AbstractedPanel.java:13
error: src/main/java/.../AbstractedPanel.java: patch does not apply

What does it mean?
How can I fix this problem?

[Assistant]
git apply --reject --whitespace=fix mychanges.patch worked for me.
Explanation
The --reject option will instruct git to not fail if it cannot determine how to apply a patch, but instead to apply the individual hunks it can apply and create reject files (.rej) for hunks it cannot apply. Wiggle can "apply [these] rejected patches and perform word-wise diffs".
Additionally, --whitespace=fix will warn about whitespace errors and try to fix them, rather than refusing to apply an otherwise applicable hunk.
Both options together make the application of a patch more robust against failure, but they require additional attention with respect to the result.
For the whole documentation, see https://git-scm.com/docs/git-apply.


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  --skip-to=<file>  --rotate-to=<file>

[Assistant]
Discard the files before the named <file> from the output
(i.e. skip to ), or move them to the end of the output
(i.e. rotate to ).  These options were invented primarily for the use
of the git difftool command, and may not be very useful
otherwise.


[System] You are a helpful assistant.

[User]
Publishing to gitlab pypi package registry for a group

I am trying to publish a package to gitlab pypi registry. What is the repository url we need to use to publish to a group package registry?.
I tried using this https://gitlab.example.com/api/v4/groups/id/packages/pypi
but it is throwing 404 now found.
The api https://gitlab.example.com/api/v4/groups/id/packages/ returns a empty array for me.
But when I manually take the registry from the UI pypy, npm etc are present.
Publishing to individual project repositories is working fine.
https://gitlab.example.com/api/v4/projects/id/packages/pypi

[Assistant]
I run into the same problem.
As far as I understand, groups don't have their own registries. If you go in your group settings, you won't see the option to activate it.
Groups are only placeholders to organize projects, they don't hold any data.
What you see in the UI when clicking on the group registry is the aggregation of all the registries of the projects inside that group.
This is only a search UI, not a registry per se.
Bottom-line is that you have to publish your artefacts to a specific project.
Note that you can have a dedicated project to hold only your registry, and have all your code repositories publish in the same registry.


[System] You are a helpful assistant.

[User]
Can I delete all the local branches except the current one?
I want to delete all branches that get listed in the output of ...
$ git branch

... but keeping current branch, in one step. Is that possible? If so, how?

[Assistant]
$ git branch | grep -v "master" | xargs git branch -D

will delete all branches except master (replace master with branch you want to keep, but then it will delete master)


[System] You are a helpful assistant.

[User]
Can I delete a git commit but keep the changes?
In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features. But just using a "git checkout master" preserved the changes I also made in my development branch, thus breaking some of the functionality in master. So what I did was commit the changes on my development branch with a commit message "temporary commit" and then checkout master for the demo.
Now that I'm done with the demo and back to work on my development branch, I would like to remove the "temporary commit" that I made while still preserving the changes I made. Is that possible?

[Assistant]
It's as simple as this:
git reset HEAD^

Note: some shells treat ^ as a special character (for example some Windows shells or ZSH with globbing enabled), so you may have to quote "HEAD^" or use HEAD~1 in those cases.
git reset without a --hard or --soft moves your HEAD to point to the specified commit, without changing any files. HEAD^ refers to the (first) parent commit of your current commit, which in your case is the commit before the temporary one.
Note that another option is to carry on as normal, and then at the next commit point instead run:
git commit --amend [-m … etc]

which will instead edit the most recent commit, having the same effect as above.
Note that this (as with nearly every git answer) can cause problems if you've already pushed the bad commit to a place where someone else may have pulled it from. Try to avoid that


[System] You are a helpful assistant.

[User]
Should I .gitignore my gradlew?

My gradle project includes gradlew and gradlew.bat files inside of the repository, should they be pushed to git or not? I did not see anybody say they should be removed here. What is the purpose of these files?

[Assistant]
NOT Really. Reason being if someone download or clone your repo and try to run your application through command line and they do not have gradle installed on their local machine, they have to install and configure Gradle and then run it. The gradlew provides a convenient way to run a gradle build with installing it.
Here is what Gradle documentation says:

Most tools require installation on your computer before you can use them. If the installation is easy, you may think that’s fine. But it can be an unnecessary burden on the users of the build. Equally importantly, will the user install the right version of the tool for the build? What if they’re building an old version of the software?
The Gradle Wrapper (henceforth referred to as the “Wrapper”) solves both these problems and is the preferred way of starting a Gradle build.


[System] You are a helpful assistant.

[User]
test after build would run in new environment on gitlab-ci

I have the following configuration as .gitlab-ci.yml
but I found out after successfully pass build stage (which
would create a virtualenv called venv), it seems that
in test stage you would get a brand new environment(there's
no venv directory at all). So I wonder should I put setup
script in before_script therefor it would run in each phase(build/test/deploy). Is it a right way to do it ?
before_script:
  - uname -r

types:
  - build
  - test
  - deploy

job_install:
  type: build
  script:
    - apt-get update
    - apt-get install -y libncurses5-dev
    - apt-get install -y libxml2-dev libxslt1-dev
    - apt-get install -y python-dev libffi-dev libssl-dev
    - apt-get install -y python-virtualenv
    - apt-get install -y python-pip
    - virtualenv --no-site-packages venv
    - source venv/bin/activate
    - pip install -q -r requirements.txt
    - ls -al
  only:
    - master

job_test:
  type: test
  script:
    - ls -al
    - source venv/bin/activate
    - cp crawler/settings.sample.py crawler/settings.py
    - cd crawler
    - py.test -s -v
  only:
    - master

adasd

[Assistant]
Gitlab CI jobs supposed to be independent, because they could run on different runners. It is not issue. There two ways to pass files between stages:

The right way. Using artefacts.
The wrong way. Using cache. With cache key "hack". Still need same runner.

So yes, supposed by gitlab way to have everything your job depends on in before script.
Artifacts example:
  artifacts:
   when: on_success
   expire_in: 1 mos
   paths:
    - some_project_files/

Cache example:
cache:
  key: "$CI_BUILD_REF_NAME"
  untracked: true
  paths:
   - node_modules/
   - src/bower_components/

For correct running environment i suggest using docker with image containing apt-get dependencies. And use artefacts for passing job results between jobs. Note that artefact also uploaded to gitlab web interface and being able to download them. So if they are quite heavy use small expire_in time, for removing them after all jobs done.


[System] You are a helpful assistant.

[User]
Accidentally committed .idea directory files into git
I have accidentally committed the .idea/ directory into git. This is causing conflicts everywhere else I need to checkout my repo. I was wondering how do I remove these files from the remote?
I still need these files locally since the Intellij IDE needs them. I just don't want them in the remote. I have added the directory .idea/ to my .gitignore and committed and pushed this file into remote. This seems to have no effect during my checkout on my other machine though. I still get the error message:
error: The following untracked working tree files would be overwritten by checkout:
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/uiDesigner.xml
.idea/vcs.xml
.idea/workspace.xml

[Assistant]
Add .idea directory to the list of ignored files
First, add it to .gitignore, so it is not accidentally committed by you (or someone else) again:
.idea

Remove it from repository
Second, remove the directory only from the repository, but do not delete it locally. To achieve that, do what is listed here:

Remove a file from a Git repository without deleting it from the local filesystem

Send the change to others
Third, commit the .gitignore file and the removal of .idea from the repository. After that push it to the remote(s).
Summary
The full process would look like this:
$ echo '.idea' >> .gitignore
$ git rm -r --cached .idea
$ git add .gitignore
$ git commit -m '(some message stating you added .idea to ignored entries)'
$ git push

(optionally you can replace last line with git push some_remote, where some_remote is the name of the remote you want to push to)


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  %at

[Assistant] author date, UNIX timestamp


[System] You are a helpful assistant.

[User]
Dealing with SVN keyword expansion with git-svn
I recently asked about keyword expansion in Git and I'm willing to accept the design not to really support this idea in Git.
For better or worse, the project I'm working on at the moment requires SVN keyword expansion like this:
svn propset svn:keywords "Id" expl3.dtx

to keep this string up-to-date:
$Id: expl3.dtx 803 2008-09-11 14:01:58Z will $

But I would quite like to use Git to do my version control. Unfortunately, git-svn doesn't support this, according to the docs:

"We ignore all SVN properties except svn:executable"

But it doesn't seem too tricky to have this keyword stuff emulated by a couple of pre/post commit hooks. Am I the first person to want this? Does anyone have some code to do this?

[Assistant]
What's going on here: Git is optimized to switch between branches as quickly as possible. In particular, git checkout is designed to not touch any files that are identical in both branches.
Unfortunately, RCS keyword substitution breaks this. For example, using $Date$ would  require git checkout to touch every file in the tree when switching branches. For a repository the size of the Linux kernel, this would bring everything to a screeching halt.
In general, your best bet is to tag at least one version:
$ git tag v0.5.whatever

...and then call the following command from your Makefile:
$ git describe --tags
v0.5.15.1-6-g61cde1d

Here, git is telling me that I'm working on an anonymous version 6 commits past v0.5.15.1, with an SHA1 hash beginning with g61cde1d. If you stick the output of this command into a *.h file somewhere, you're in business, and will have no problem linking the released software back to the source code. This is the preferred way of doing things.
If you can't possibly avoid using RCS keywords, you may want to start with this explanation by Lars Hjemli. Basically, $Id$ is pretty easy, and you if you're using git archive, you can also use $Format$.
But, if you absolutely cannot avoid RCS keywords, the following should get you started:
git config filter.rcs-keyword.clean 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"'
git config filter.rcs-keyword.smudge 'perl -pe "s/\\\$Date[^\\\$]*\\\$/\\\$Date: `date`\\\$/"'

echo '$Date$' > test.html
echo 'test.html filter=rcs-keyword' >> .gitattributes
git add test.html .gitattributes
git commit -m "Experimental RCS keyword support for git"

rm test.html
git checkout test.html
cat test.html

On my system, I get:
$Date: Tue Sep 16 10:15:02 EDT 2008$

If you have trouble getting the shell escapes in the smudge and clean commands to work, just write your own Perl scripts for expanding and removing RCS keywords, respectively, and use those scripts as your filter.
Note that you really don't want to do this for more files than absolutely necessary, or git will lose most of its speed.


[System] You are a helpful assistant.

[User]
How can I add a file to the last commit in Git? [duplicate]
This question already has answers here:

How to modify existing, unpushed commit messages?

                                (27 answers)

Closed 7 years ago.

Sometimes after I did a commit, I found out that I left out a file which should also be included in the commit, but was actually not. I often committed again:
git add the_left_out_file
git commit "include the file which should be added in the last commit"

I think it might not be a good idea to do so. I want to just include the file without adding a commit. Something like this,
git add the_left_out_file
git add_staged_files_to_previous_commit

Is it possible?

[Assistant]
Yes, there's a command, git commit --amend, which is used to "fix" the last commit.
In your case, it would be called as:
git add the_left_out_file
git commit --amend --no-edit

The --no-edit flag allows to make an amendment to the commit without changing the commit message.
Warning
You should never amend public commits that you already pushed to a public repository, because amend is actually removing the last commit from the history and creating a new commit with the combined changes from that commit and new added when amending.


[System] You are a helpful assistant.

[User]
How do I clean up my Github fork so I can make clean pull requests?

I forked a repository on Github. I've made some minor changes and submitted pull requests to the upstream, but along the way my fork has become so mangled I'm unable to generate clean pull requests; when I start a pull request from a branch with six changes, Github wants to submit thirteen, with seven of them already existing upstream (natch).
My problem seems to be related to only pulling the latest commits, but when I create a new branch and cherry-pick commits I still have extras. I've futzed with rebasing as well, but now it looks like even my master is so messed up I can't generate a clean copy of upstream. This is apparently because I didn't understand that I needed to rebase instead of merging, so clearly I've made mistakes; what I'm trying to do is figure out how to unsnarl that knot and get back to a clean state where I can move forward usefully.
I kind of want to blow away my fork and make a new fork of the upstream, but I gather that, too, is difficult.
Having confessed my Git sins, how do I obtain github absolution?

[Assistant]
Step 1: Pull upstream changes
It's recommended to add the upstream repo as "upstream" as explained on the Fork a Repo page:
git pull --rebase upstream master

The --rebase option places your changes on top of the latest commit without merges.
Step 2: (Optional) Merge your commits into 1 commit
git reset --soft upstream/master

This command will "undo" all your commits, but won't change the files. So you can commit all your changes in a single commit.
git commit -a

Step 3: Check & test your changes
To show the changes use a GUI like the built-in gitk, Sourcetree, TortoiseGit or Tower (paid), etc.
Step 4: Push
git push will throw an error, because the push would change the target repository's history.
If you're confident the changes shown in step 3 are correct then push with "-f"
git push -f origin master

Additional information
The command to add a remote is:
git remote add upstream git://github.com/[username]/[project].git

You can also also pull from a direct URL:
git pull --rebase  git://github.com/[username]/[project].git

But then you'll need the hash of the latest upstream commit instead of "upstream/master" in the other steps.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-help

[Assistant] Display help information about Git


[System] You are a helpful assistant.

[User]
How to remove a dangling commit from GitHub?

Yesterday, I pushed to my fork of ConnectBot on GitHub. I pushed once, realized that I hadn't made the change the way I wanted, redid the commit and pushed again.
Now, GitHub has both commits:

https://github.com/nylen/connectbot/commit/1cd775d – the first, “bad” commit
https://github.com/nylen/connectbot/commit/987671c – the one I want to keep

My master branch is only tracking the second commit, but the first commit is still available and is still in my activity feed.  How can I remove it to make sure no one accidentally pulls that commit instead of the corrected version?

[Assistant]
If you really need it to be removed immediately, you would probably have to contact GitHub Support.
Pulling should generate a pack that contains only objects that are referenced so no one should get that commit as a result of a clone or a pull.  For example,
$ git clone git://github.com/nylen/connectbot.git
Cloning into connectbot...
remote: Counting objects: 6261, done.
remote: Compressing objects: 100% (1900/1900), done.
remote: Total 6261 (delta 3739), reused 5980 (delta 3520)
Receiving objects: 100% (6261/6261), 3.04 MiB | 3.40 MiB/s, done.
Resolving deltas: 100% (3739/3739), done.
$ git cat-file -t 1cd775d
fatal: Not a valid object name 1cd775d