[System] You are a helpful assistant.

[User]
Pull Request, ignore some file changes
When I do a Pull Request on GitHub (against master branch), can we ignore some file changes, like

we have one file named 'fileA' in branch 'release', and we have the same file in 'master', but we do some changes in 'fileA' in branch 'release'
when we do a Pull Request, is there any way we can ignore the changes in 'fileA', do not let that merge into 'master'.

[Assistant]
You can't ignore some files from a pull request selectively.
Two workarounds for this can be -
First -

Create a new branch from 'release'
Replace the non-required files from 'master'
Create pull request from this new branch

Second -

Create a new branch from 'master'
Put changes of required files from 'release'
Create pull request from this new branch

Any of this method will work. Which will be easier depends upon how many files are to be included / excluded.


[System] You are a helpful assistant.

[User]
How to connect to a target server via SSH with a key from a GitLab pipeline?

I want to connect to a server via SSH with a public key when GitLab pipeline succeeds.
As I see, I need to generate a key with ssh-keygen on GitLab side and add it to server where I want to connect.
I can generate a key during the pipeline but as the public key is not added to the target server, it makes no sense.
I suppose it's a common scenario to connect from a CI build to a remote SSH with a key.
How can I make it work?

[Assistant]
You can run ssh-keygen from wherever you want as long as you use the appropriate keys on the appropriate server.
Here is what you need:

Generate a key pair
Copy the private key to a gitlab CI variable (let's call it SSH_PRIVATE_KEY)
Copy the public key to the server gitlab will connect to and add it to your ~/.ssh/authorized_keys file
Tell your CI pipeline to use the private key that is stored in the Gitlab CI variable

In order to do that last step, just add the following to your .gitlab-ci.yml in the script or before_script section of the job of interest:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

Then do your SSH connections and voilà !
EDIT: I couldn't remember where I had found this info the first time but here it is : https://docs.gitlab.com/ee/ci/ssh_keys/README.html


[System] You are a helpful assistant.

[User]
Error when using Git credential helper with gnome-keyring as Sudo
I was looking for a way to store credentials securely while connecting to our Git server which uses SSL. I came across this suggestion by @james-ward (only edit I made was I updated our "system" config instead of our "global" config for Git (https://stackoverflow.com/a/14528360/6195194)
sudo apt-get install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --system credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring

I then can run
git clone https://ipaddress/git/repo.git

and the credential helper will store my credentials, however when I run the following:
sudo git clone https://ipaddress/git/repo.git testfolder

it give me the following error
** (process:3713): CRITICAL **: Error communicating with gnome-keyring-daemon

I sometimes need to run sudo git clone since sometimes the directory where I need to make a clone requires it. Any help would be appreciated.
Versions I am using:
 - git version 1.9.1
 - Ubuntu Server 14.0.4
Thank you in advance!
-Richard O.

[Assistant]
Beside the use of sudo, note that in 2016, libgnome-keyring is specific to GNOME and is now deprecated (since January 2014, actually).
2022 option: git-credential-manager
Microsoft provides a cross-platform  credential helper named GCM (Git Credential Manager), which you can install (no need to build it) and configure:
git-credential-manager-core configure

You will need Git 2.27+ to use it.
Q4 2022: GCM is now Git Credential Manager (no more -core)
git-credential-manager configure

You will need Git 2.38.1+ to use it.

2016 option: git-credential-libsecret
Git 2.11+ (Q4 2016) included a new credential helper using libsecret.
See commit 87d1353 (09 Oct 2016) by Mantas Mikulėnas (grawity).
(Merged by Junio C Hamano -- gitster -- in   commit bfe800c, 26 Oct 2016)

A new credential helper that talks via "libsecret" with implementations of XDG Secret Service API has been added to contrib/credential/.
it uses libsecret which can support other implementations of XDG Secret
Service API.

But in 2022, this is no longer needed. See above

As noted by mati865 in the comments:

It should be noted that some distros like Arch and Fedora provide helpers available as both binary and source.

Libsecret binary on Arch: /usr/lib/git-core/git-credential-libsecret, and
Libsecret binary on Fedora: /usr/libexec/git-core/git-credential-libsecret.

Note: As @rugk adds in the comments, for Fedora and Git v2.25.2-1 or higher, you need to install an extra package with that binary, because it has been split from the main git package:
dnf install git-credential-libsecret

Git 2.41 (Q2 2023) clarifies:
See commit 0a3a972, commit 64f1e65, commit de2fb99, commit 048b673, commit 5747c80, commit 71201ab, commit 16b305c (01 May 2023) by Taylor Blau (ttaylorr).
(Merged by Junio C Hamano -- gitster -- in commit fbbf60a, 10 May 2023)

contrib/credential: remove 'gnome-keyring' credential helper
Co-authored-by: Jeff King
Signed-off-by: Jeff King
Signed-off-by: Taylor Blau

libgnome-keyring was deprecated in 2014 (in favor of libsecret), more than nine years ago.
The credential helper implemented using libgnome-keyring has had a small handful of commits since 2013, none of which implemented or changed any functionality.
The last commit to do substantial work in this area was 15f7221 ("contrib/git-credential-gnome-keyring.c: support really ancient gnome-keyring", 2013-09-23, Git v1.8.5-rc0 -- merge), just shy of nine years ago.
This credential helper suffers from the same fgets()-related injection attack (using the new "wwwauth[]" feature) as in the previous commit.
Instead of patching it, let's remove this helper as deprecated.


[System] You are a helpful assistant.

[User]
How do I squash two non-consecutive commits?
I'm a bit new to the whole rebasing feature within git.  Let's say that I made the following commits:
A -> B -> C -> D

Afterwards, I realize that D contains a fix which depends on some new code added in A, and that these commits belong together.  How do I squash A & D together and leave B & C alone?

[Assistant]
You can run git rebase --interactive and reorder D before B and squash D into A.
Git will open an editor, and you see a file like this, ex: git rebase --interactive HEAD~4
pick aaaaaaa Commit A
pick bbbbbbb Commit B
pick ccccccc Commit C
pick ddddddd Commit D

# Rebase aaaaaaa..ddddddd onto 1234567 (4 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

Now you change the file that it looks like this:
pick aaaaaaa Commit A
squash ddddddd Commit D
pick bbbbbbb Commit B
pick ccccccc Commit C

And git will now meld the changes of A and D together into one commit, and put B and C afterwards. When you don't want to keep the commit message of D, instead of squash, you would use the fixup keyword. For more on fixup, you can consult the git rebase docs, or check out this question which has some good answers.


[System] You are a helpful assistant.

[User]
How do I delete a Git branch with TortoiseGit
Is there an option to delete a branch with TortoiseGit?
I found a solution for the commandline. Is there an implementation in TortoiseGit?

[Assistant]
You should read this article: Remote branches with TortoiseGit
According to this blog post:
...remove the local branch by first opening up the Checkout/Switch dialog to get at the Browse refs dialog.

In the Browse refs dialog we can right click on the local branch and choose to delete it.

To delete a remote branch we can do the same thing, but instead of right clicking on our local branch we expand the remotes tree in the left part of the dialog and then locate the remote branch.


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  attr

[Assistant]
After attr: comes a space separated list of "attribute
requirements", all of which must be met in order for the
path to be considered a match; this is in addition to the
usual non-magic pathspec pattern matching.
See gitattributes . Each of the attribute requirements for the path takes one of
these forms: " ATTR " requires that the attribute ATTR be set. " -ATTR " requires that the attribute ATTR be unset. " ATTR=VALUE " requires that the attribute ATTR be
set to the string VALUE . " !ATTR " requires that the attribute ATTR be
unspecified. Note that when matching against a tree object, attributes are still
obtained from working tree, not from the given tree object.


[System] You are a helpful assistant.

[User]
Git pull/push error: RPC failed; result=22, HTTP code = 408

I am new to GIT. I am using Git version 1.7.9.5.
I am working on project hosted on github. While pushing and pulling the code from github sometime it works fine and some time it gives me error.

error: RPC failed; result=22, HTTP code = 408
fatal: The remote end hung up unexpectedly

I don't what is going wrong. If anyone can suggest me something what could possibly be the issue.

[Assistant]
The problem is due to git/https buffer settings. In order to solve it run this below command:-
git config http.postBuffer 524288000

And try git push again


[System] You are a helpful assistant.

[User] git-clean - Remove untracked files from the working tree  -f  --force

[Assistant]
If the Git configuration variable clean.requireForce is not set
to false, git clean will refuse to delete files or directories
unless given -f.  Git will refuse to modify untracked
nested git repositories (directories with a .git subdirectory)
unless a second -f is given.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  GIT_DISCOVERY_ACROSS_FILESYSTEM

[Assistant]
When run in a directory that does not have ".git" repository
directory, Git tries to find such a directory in the parent
directories to find the top of the working tree, but by default it
does not cross filesystem boundaries.  This Boolean environment variable
can be set to true to tell Git not to stop at filesystem
boundaries.  Like GIT_CEILING_DIRECTORIES , this will not affect
an explicit repository directory set via GIT_DIR or on the
command line.


[System] You are a helpful assistant.

[User]
Reapply a commit that was undone by conflict?

I have this commit that was undone by someone who doesn't know how to deal with conflicts. Is there an easy way to try auto merging the commit back in? I tried using "merge to master" but it just says up to date. I am using tortoisegit.

[Assistant]
That's what git cherry-pick is for. It lets you apply changes by using already existing commits.
The basic syntax is:
git cherry-pick <commit> ...


[System] You are a helpful assistant.

[User]
Where did git put a clone

I'm pretty new to git. For a class the teacher posted a link to clone a project file it said
git clone git://github.com/foo

I typed the command and it seemed to work. Problem is I don't know where the file is! If I type the command again it says destination path already exists and is not an empty directory.
Any help really appreciated =S

[Assistant] The repository should have been cloned into a directory named "foo" located in whichever directory you ran the git clone command from.


[System] You are a helpful assistant.

[User]
Is proprietary code legally safe on bitbucket or github? [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

The community reviewed whether to reopen this question 10 months ago and left it closed:

Original close reason(s) were not resolved

                        Improve this question

I know this slightly in the legal realm but its unclear who owns the code if you put proprietary code on github or bitbucket in a private repository.
From Bitbucket we have:

By submitting public (non-private)
  Content to Avantlumiere for inclusion
  on your Website, you grant
  Avantlumiere a world-wide,
  royalty-free, and non-exclusive
  license to reproduce, modify, adapt
  and publish the Content solely for the
  purpose of displaying and promoting
  your account or repository. If a
  repository is marked as private, these
  terms do not apply.

The question of course is what terms do apply to private accounts.
In theory the code should be safe if a license header with copyright information is on every file... right?
I am not asking for legal advice and will not hold any one responsible.

[Assistant]
From GitHub:

We claim no intellectual property rights over the material you provide to the Service. Your profile and materials uploaded remain yours. However, by setting your pages to be viewed publicly, you agree to allow others to view your Content. By setting your repositories to be viewed publicly, you agree to allow others to view and fork your repositories.

As noted in the BitBucket TOS you linked, BitBucket's parent company similarly has no claims to code that you upload into private repos.


[System] You are a helpful assistant.

[User]
How to convert a normal Git repository to a bare one?
How can I convert a 'normal' Git repository to a bare one?
The main difference seems to be:

in the normal Git repository, you have a .git folder inside the repository containing all relevant data and all other files making up your working copy
in a bare Git repository, there is no working copy and the folder (let's call it repo.git) contains the actual repository data

[Assistant]
In short: replace the contents of repo with the contents of repo/.git, then tell the repository that it is now a bare repository.
To do this, execute the following commands:
cd repo
mv .git ../repo.git # renaming just for clarity
cd ..
rm -fr repo
cd repo.git
git config --bool core.bare true

Note that this is different from doing a git clone --bare /path/to/repo to a new location (as described here).
Consider this scenario

Your origin had 100 branches

You have only checked out 10 of them locally
Your bare repo will only have the 10

You send the bare repo somewhere

It would be missing 90 branches

If that's your intention, that's fine. If you needed a mirror of the remote/origin, this is not the way.


[System] You are a helpful assistant.

[User]
Remove commit from history
I entered a curseword in my code and I pushed the code on the master branch. I pushed a few more times after that so people do not pull the bad stuff, but I can still find the curseword in the commits history.
I don't want to add the file to .gitignore because we need that file.
Is there a way to delete the commit from history?

[Assistant]
Once you push to the repo, you really don't want to go about changing history. However, if you are absolutely sure that nobody has pulled/fetched from the repo since your offending commit, you have 2 options.
If you want to remove the "bad" commit altogether (and every commit that came after that), do a git reset --hard ABC (assuming ABC is the hash of the "bad" commit's elder sibling — the one you want to see as the new head commit of that branch). Then do a git push --force (or git push -f).
If you just want to edit that commit, and preserve the commits that came after it, do a git rebase -i ABC~. This will launch your editor, showing the list of your commits, starting with the offending one. Change the flag from "pick" to "e", save the file and close the editor. Then make the necessary changes to the files, and do a git commit -a --amend, then do git rebase --continue. Follow it all up with a git push -f.
I want to repeat, these options are only available to you if nobody has done a pull or fetch that contains your offending commit. If they have, doing these steps will just make matters worse.


[System] You are a helpful assistant.

[User]
Git - Won't add files?
I'm having issues where I can't add files to my repository.
I'm using GIT on windows, in Aptana Studio for some Ruby development.
I've managed to push a few files up to GitHub, but then after this, everything's stopped working. I have for example a new sub-folder in my master directory, with 2 ruby files inside. If I call "git add .", and then "git status" and it keeps saying "working directory clean" and has nothing to commit.
I've tried "git add folder/myfile.rb" and still nothing.
Anyone any idea's what I can try?

[Assistant]
I found myself in a similar situation as the poster:

If I call "git add .", and then "git status" and it keeps saying
"working directory clean" and has nothing to commit.

But I had a different solution than what's here. Since I came to this first, I hope to save others some time.
From the above answers and what I've seen elsewhere, the usual fixes to this problem are:

Ensure there are actually saved changes on the file in question
Ensure the file doesn't meet your exclude rules in .gitignore and .git/info/exclude
Ensure you're not trying to add an empty folder. Git won't track those. Standard solution is to place a blank file named .gitkeep as a placeholder so git will track the folder.

In my case, I had originally tried to create a git repo around an existing repo (not knowing it was there). I had removed the .git folder from this sub repo a while ago, but I didn't realize that it was too late, and git was already tracking it as a submodule. You can read more about how these behave and how to remove them here, but

the solution for me was to simply run git rm --cached path_to_submodule.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  mergetool.guiDefault

[Assistant]
Set true to use the merge.guitool by default (equivalent to
specifying the --gui argument), or auto to select merge.guitool or merge.tool depending on the presence of a DISPLAY environment
variable value. The default is false , where the --gui argument
must be provided explicitly for the merge.guitool to be used.


[System] You are a helpful assistant.

[User]
Change from master to a new default branch git

Here is a scenerio:
We have a default branch master and we work off from this, creating branches and pushing up etc...
We have now created a develop branch off master and set this as a default development branch.
What I would like to know is, how do I now know if my git pull command is requesting changes from the default branch via the command line? or point to this new default branch?
What I have done:

Since creating a new default branch git pull into master from origin/master

Also, any new branch, will it be from master or develop?
As you can see
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
PS C:\Users\dir\Documents\GitHub\repo> git log
commit 867cxx

fd956f73dc91d0022b (HEAD -> master, origin/master, origin/develop, origin/HEAD)

update:
this change of default branch occurred after cloning the repo.

[Assistant]
With git 2.28 you can set a global config with this command
git config --global init.defaultBranch {branchName}
Replace {branchName} with the default branch name
and now whenever you create a new git repo, the default branch will be this.
More details in my video here: https://www.youtube.com/watch?v=YccHk6QlRss


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  working tree

[Assistant]
The tree of actual checked out files.  The working tree normally
contains the contents of the HEAD commit’s tree,
plus any local changes that you have made but not yet committed.


[System] You are a helpful assistant.

[User]
git: checkout files from another branch into current branch (don't switch HEAD to the other branch)
I want to load a different version of the files that exist in another branch into my current branch.
git help checkout says:
DESCRIPTION
   Updates files in the working tree to match the version in the index or
   the specified tree. If no paths are given, git checkout will also
   update HEAD to set the specified branch as the current branch.

Is there a way to checkout all those files, but not update HEAD?

[Assistant]
checkout by providing the current path, .:
git checkout other-branch-name -- .
This operation is similar to switching HEAD to another branch without checking out files, but just from the "other direction".
As @김민준 mentions, this overwrites any uncommitted changes. Remember to either stash or commit them somewhere first if needed.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  GIT_SSH  GIT_SSH_COMMAND

[Assistant]
If either of these environment variables is set then git fetch and git push will use the specified command instead of ssh when they need to connect to a remote system.
The command-line parameters passed to the configured command are
determined by the ssh variant.  See ssh.variant option in git-config for details. $GIT_SSH_COMMAND takes precedence over $GIT_SSH , and is interpreted
by the shell, which allows additional arguments to be included. $GIT_SSH on the other hand must be just the path to a program
(which can be a wrapper shell script, if additional arguments are
needed). Usually it is easier to configure any desired options through your
personal .ssh/config file.  Please consult your ssh documentation
for further details.


[System] You are a helpful assistant.

[User] git-merge - Join two or more development histories together  --stat  -n  --no-stat

[Assistant]
Show a diffstat at the end of the merge. The diffstat is also
controlled by the configuration option merge.stat. With -n or --no-stat do not show a diffstat at the end of the
merge.


[System] You are a helpful assistant.

[User] git-checkout - Switch branches or restore working tree files  -B <new-branch>

[Assistant]
Creates the branch <new-branch> , start it at <start-point> ;
if it already exists, then reset it to <start-point> . And then
check the resulting branch out.  This is equivalent to running
"git branch" with "-f" followed by "git checkout" of that branch;
see git-branch for details.


[System] You are a helpful assistant.

[User] gitfaq - Frequently asked questions about using Git  I’ve made a mistake in the last commit.  How do I change it?

[Assistant]
You can make the appropriate change to your working tree, run git add
<file> or git rm <file> , as appropriate, to stage it, and then git
commit --amend .  Your change will be included in the commit, and you’ll
be prompted to edit the commit message again; if you wish to use the
original message verbatim, you can use the --no-edit option to git
commit in addition, or just save and quit when your editor opens.


[System] You are a helpful assistant.

[User]
How to use Git and Dropbox together? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers.

Closed 3 years ago.

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.

Is it possible to use Git and Dropbox together?

[Assistant]
I think that Git on Dropbox is great. I use it all the time. I have multiple computers (two at home and one at work) on which I use Dropbox as a central bare repository. Since I don’t want to host it on a public service, and I don’t have access to a server that I can always SSH to, Dropbox takes care of this by syncing in the background (very doing so quickly).
Setup is something like this:
~/project $ git init
~/project $ git add .
~/project $ git commit -m "first commit"
~/project $ cd ~/Dropbox/git

~/Dropbox/git $ git init --bare project.git
~/Dropbox/git $ cd ~/project

~/project $ git remote add origin ~/Dropbox/git/project.git
~/project $ git push -u origin master

From there, you can just clone that ~/Dropbox/git/project.git directory (regardless of whether it belongs to your Dropbox account or is shared across multiple accounts) and do all the normal Git operations—they will be synchronized to all your other machines automatically.
I wrote a blog post “On Version Control” in which I cover the reasoning behind my environment setup. It’s based on my Ruby on Rails development experience, but it can be applied to anything, really.


[System] You are a helpful assistant.

[User]
Is there a way to lock a branch in GIT
I have an idea of locking a repository from users pushing files into it by having a lock script in the GIT update hook since the push can only recognize the userid as arguments and not the branches. So i can lock the entire repo which is just locking a directory.
Is there a way to lock a specific branch in GIT?
Or is there a way an Update Hook can identify from which branch the user is pushing and to which branch the code is pushed?

[Assistant]
The branch being pushed to is the first parameter to the update hook. If you want to lock the branch myfeature for pushing, this code (placed in hooks/update) will do it:
#!/bin/sh
# lock the myfeature branch for pushing
refname="$1"

if [[ $refname == "refs/heads/myfeature" ]]
then
    echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    echo "You cannot push to myfeature! It's locked"
    echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    exit 1
fi
exit 0


[System] You are a helpful assistant.

[User] git-grep - Print lines matching a pattern  -n  --line-number

[Assistant] Prefix the line number to matching lines.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  --icase-pathspecs

[Assistant]
Add "icase" magic to all pathspec. This is equivalent to setting
the GIT_ICASE_PATHSPECS environment variable to 1 .


[System] You are a helpful assistant.

[User]
git log and show on a bare repo
I created a bare repository on a file-server in my local network at home.
After this i pushed a branch of an existing repository from my desktop-pc to this new remote repository.
Pushing worked perfectly and it seems, that all data arrived (a "git branch -va" gives me the correct data).
But i cannot use git log or git show on the bare repository.
i get an:
fatal: bad default revision 'HEAD'
or simply no output
is this normal for bare repositories? Is there another possibility to visualize everything?
Edit:
The fatal error is solved now, but i receive no output from "git log" or "git log unstable". Same command on the desktop-pc works perfectly

[Assistant]
Yes, this is normal for new bare (and non-bare) repositories.
Explanation
HEAD is what Git calls a symbolic reference—a reference to another reference.
In non-bare repositories, HEAD normally indicates which branch is currently checked out.  A new commit will cause the branch named by HEAD to be advanced to refer to the new commit.  When HEAD refers to a commit object directly instead of a branch, it's considered to be detached, meaning further commits will not cause a branch reference to be advanced to refer to the new commits (dangerous because checking out a different commit or branch will render the new commits unreachable by any existing reference, making them hard to find and subject to garbage collection).
In bare repositories, HEAD indicates the repository's default branch, so that in a clone of the repository git checkout origin is equivalent to git checkout origin/master if master is the default branch (see git help rev-parse for details).
When Git initializes a new repository, it initializes HEAD to refer to refs/heads/master (in other words, HEAD points to the master branch by default).  However, it does not create a branch named master because there are no commits in the repository for master to point to yet.
So until you either create a master branch or change HEAD to point to a branch that does exist, you'll get that error when you run a command that looks at HEAD (such as git log or git show without any arguments).
You can still use commands that don't examine HEAD.  For example:
git log some_branch_that_exists

Fix
To get rid of the error message, you can do one of the following:

Change HEAD to point to a branch that does exist:
git symbolic-ref HEAD refs/heads/some_other_branch

Push a new master branch into the repository from somewhere else
Create a new master branch locally:
git branch master some_existing_commit

Visualization
To visualize everything in the repository, I use something like this:
git log --graph --oneline --date-order --decorate --color --all

Note that the above command will work even if HEAD is pointing to a non-existent branch.


[System] You are a helpful assistant.

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

[Assistant] Pass --verbose to git-fetch and git-merge.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  <object>

[Assistant] Indicates the object name for any type of object.


[System] You are a helpful assistant.

[User]
Merge git repo into branch of another repo
Given repo Foo and repo Bar. I want to merge Bar with Foo, but only into a separate branch, called baz.
git switch -c baz <= put the Bar repo here.

[Assistant]
You can't merge a repository into a branch.  You can merge a branch from another repository into a branch in your local repository.
Assuming that you have two repositories, base-repo and other-repo, where you want to merge other-repo into base-repo:
Change into the base-repo repository:
$ cd base-repo

Add the other-repo repository as a remote and fetch it:
$ git remote add other-repo [email protected]:xxx/other-repo.git # or use a path like ../foo if you have it locally on your machine
$ git remote update

Create a new branch base-with-other in the base-repo based on whatever your current branch is:
$ git switch -c base-with-other # choose any branch name you want and put it after -c

Merge branch somebranch from the other-repo into the current branch:
$ git merge --allow-unrelated-histories other-repo/somebranch

(--allow-unrelated-histories is not required prior to git version 2.9)


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  diff.tool

[Assistant]
Controls which diff tool is used by git-difftool .
This variable overrides the value configured in merge.tool .
The list below shows the valid built-in values.
Any other value is treated as a custom diff tool and requires
that a corresponding difftool.<tool>.cmd variable is defined.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  rmHints

[Assistant]
Shown on failure in the output of git-rm , to
give directions on how to proceed from the current state.


[System] You are a helpful assistant.

[User]
Git rebase failing

I'm trying to rebase the work of a colleague.
First, I get a ton of conflicts where <<<<< head seams to contain the new code.
Then after a while I get the following error:
fatal: update_ref failed for ref 'refs/heads/dev_504':
cannot lock ref     'refs/heads/dev_504': ref refs/heads/dev_504 is at
 XXXXXXX
 but expected     XXXXXXXX
Could not move back to refs/heads/dev_504

Then if I try to continue anyway I get the following error:
fatal: cannot resume: .git/rebase-apply/final-commit does not exist.

How can I fix this so the rebase won't give an error?

[Assistant]
You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called.
You can run git rebase --skip to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option.
You can fix the conflict.
Failing that, you should re-create your branch or you can be able to remove the .git/rebase-merge directory, which contains the rebase state.


[System] You are a helpful assistant.

[User]
Modify PATH for gitlab-runner

I want to install a gitlab-runner (executor shaell) on my Windows 10 box. I start the job on the gitlab server and it always ends up with the message the command "git" cannot be found (roughly translated into english).
As a matter of fact git is not part of my path.
How can I modify my PATH variable for the shell the gitlab-runner starts?
To use git on the command line in windows I usually set it with the statement: PATH %PATH%C:\Program Files\Git\bin.
Is it documented somewhere, git has to be available to the runner?
How can I see the command line the runner invokes (i.e. the call to git)?

[Assistant]
This GitLab Runner issue answers your question.
The environment setting doesn't work since it gets evaluated before the variables are set, but you can use pre_build_script in the runner config to update the path.
[[runners]]
  name = "My Runner"
  url = "https://gitlab.com/"
  token = "Abcd1234"
  executor = "shell"
  pre_build_script = "set Path=%GIT_HOME%\\usr\\bin;%Path%"


[System] You are a helpful assistant.

[User] git-send-email - Send a collection of patches as emails  --smtp-domain=<FQDN>

[Assistant]
Specifies the Fully Qualified Domain Name (FQDN) used in the
HELO/EHLO command to the SMTP server.  Some servers require the
FQDN to match your IP address.  If not set, git send-email attempts
to determine your FQDN automatically.  Default is the value of sendemail.smtpDomain .


[System] You are a helpful assistant.

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

[Assistant]
Interactively choose hunks of patch between the index and the
work tree and add them to the index. This gives the user a chance
to review the difference before adding modified contents to the
index. This effectively runs add --interactive , but bypasses the
initial command menu and directly jumps to the patch subcommand.
See “Interactive mode” for details.


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  --find-object=<object-id>

[Assistant]
Look for differences that change the number of occurrences of
the specified object. Similar to -S , just the argument is different
in that it doesn’t search for a specific string but for a specific
object id. The object can be a blob or a submodule commit. It implies the -t option in git-log to also find trees.


[System] You are a helpful assistant.

[User]
How do I reverse a commit in git?

I'm not really familiar with how git works. I pushed a commit by mistake and want to revert it. I did a
git reset --hard HEAD~1

Beware Fellow Googlers: This does not only revert the commit, but discards all file changes!
and now the project is reverted on my machine, but not on github. If I try to push this code, I get the error 'Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.' How do I remove this commit from github?

[Assistant]
This article has an excellent explanation as to how to go about various scenarios (where a commit has been done as well as the push OR just a commit, before the push):
From the article, the easiest command I saw to revert a previous commit by its commit id, was:
git revert dd61ab32


[System] You are a helpful assistant.

[User]
How do I interactively unstage a particular hunk in git?
In git, if I have a couple of hunks from the same file staged in my index, how can I interactively unstage one of them?
Is there any alternative to unstaging the entire file, and then re-staging the hunks I want to keep, or manually undoing the changes to the working copy, and then interactively adding those undone changes?

[Assistant] Try git reset --patch filename; this should do the opposite of git add --patch, according to the documentation. The short form -p also works for both commands.


[System] You are a helpful assistant.

[User]
How to use Go with a private GitLab repo
GitLab is a free, open-source way to host private .git repositories but it does not seem to work with Go. When you create a project it generates a URL of the form:
[email protected]:private-developers/project.git

where:

1.2.3.4 is the IP address of the gitlab server
private-developers is a user group which has access to the private repo

Golang 1.2.1 doesn't seem to understand this syntax.
go get [email protected]:private-developers/project.git

results in:
package [email protected]/project.git: unrecognized import path "[email protected]/project.git"

Is there a way to get this to work?

[Assistant]
Run this command:
git config --global url."[email protected]:".insteadOf "https://1.2.3.4/"

Assuming you have the correct privileges to git clone the repository, this will make go get work for all repos on server 1.2.3.4.
I tested this with go version 1.6.2, 1.8, and 1.9.1.


[System] You are a helpful assistant.

[User]
How to stash only unstaged changes in Git?
I would like to use this workflow:

Stage some changes.
Save the unstaged changes to the stash.
Do some stuff with the things in stage (build, test, etc.).
Commit.
Restore the unstaged changes.

Is there a way to do step 2?
Example:
git init
echo one >file
git add file
git commit
echo two >>file
git add file
echo three >>file
git stash push
test
git commit
git stash pop

[Assistant]
git stash push has an option --keep-index that does exactly what you need, so run:
git stash push --keep-index


[System] You are a helpful assistant.

[User] git-for-each-ref - Output information on each ref  --stdin

[Assistant]
If --stdin is supplied, then the list of patterns is read from
standard input instead of from the argument list.


[System] You are a helpful assistant.

[User] git-format-patch - Prepare patches for e-mail submission  --patience

[Assistant] Generate a diff using the "patience diff" algorithm.


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  git-diff-index <tree-ish>

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


[System] You are a helpful assistant.

[User]
Empty Git submodule folder when repo cloned
I have one repo hosted at https://github.com/aikiframework/json. On my local copy, I added a submodule using the command:
git submodule add [email protected]:jcubic/json-rpc.git json-rpc

Then I did a commit and push, and the changes appear on GitHub (I can click on it). But when I clone the repo:
git clone https://github.com/aikiframework/json.git

the submodule folder json-rpc is empty.
What am I missing here? Did I forget about something? Why is that folder empty?

[Assistant]
OK I found it, needed to add --recursive when cloning the repo.
So the clone command ends up as:
git clone https://github.com/aikiframework/json.git --recursive

Note that if you forgot the --recursive flag you can do (thanks to @Amber):
git submodule update --init

Note that when submodules have other submodules you need recursive option (thanks for @cpprust):
git submodule update --init --recursive


[System] You are a helpful assistant.

[User]
Integrate Gitlab and TravisCi

Is there a way where I can integrate TravisCi with Giltab? or at least logging in TravisCi using username and password and not Github credentials?

[Assistant]
No, as of right now, Travis-CI is strictly bound to GitHub. While there are certainly talks about lessening this requirement, it's still there for still some time to come.
As a workaround, you could push your stuff to GitHub and from there to Travis, using GitHub only as an intermediary.


[System] You are a helpful assistant.

[User]
How to clone a specific Git tag
From git-clone(1) Manual Page

--branch can also take tags and detaches the HEAD at that commit in the resulting repository.

I tried
git clone --branch <tag_name> <repo_url>

But it does not work. It returns:
warning: Remote branch 2.13.0 not found in upstream origin, using HEAD instead

How to use this parameter?

[Assistant]
git clone --depth 1 --branch <tag_name> <repo_url>

--depth 1 is optional but if you only need the state at that one revision, you probably want to skip downloading all the history up to that revision.


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  head

[Assistant] A named reference to the commit at the tip of a branch .  Heads are stored in a file in $GIT_DIR/refs/heads/ directory, except when using packed refs. (See git-pack-refs .)


[System] You are a helpful assistant.

[User]
Compare old and new versions of force-pushed GitHub pull request

Frequently, my colleagues will make some changes to an open pull request, rebase their local branch against the base branch - often squashing their changes into previous commits as well - and force-push.
How can I see what changed between the old version of the PR and the new version of the PR?
I guess I could do a git pull and git checkout $BRANCH_NAME when the PR was first raised, then git fetch and then git diff $BRANCH_NAME..origin/$BRANCH_NAME after the PR was updated - but that will also show changes that have been introduced into the base branch (typically master) and brought into the PR via a rebase. Is it possible to remove that noise and just show what has changed in the PR itself?

[Assistant]
the old version of the PR

You can do so directly on GitHub: see "Find committer of a force push on GitHub"

Clicking the “force-pushed” link will show a two dot comparison between the two commits.

Original answer: 2016
That would be only available in the reflog of the remote repo, which would include the previous HEAD of the branch force-pushed.
Since the remote repo is a GitHub one, you still can infer the old commit by looking at push events: see "Does github remember commit IDs?".

hat will also show changes that have been introduced into the base branch (typically master)

More exactly, you will always have the differences against a common ancestor (which will include commits from the base branch like master)
See What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?

So in your case, your forced-pushed branch looks like this on the remote repo:
      x--x--x        (old branch in reflog)
     /
 m--M0--M--M   (master)
            \
             X--X--X (new branch forced push)

A diff old_HEAD..newHEAD would include the few M commits from the base branch, as they are part of the common ancestor (M0) path.
So you can compare a force-pushed branch (providing you are monitoring pushEvents and know of the previous HEAD of that branch).
But uou cannot easily compare two branches without their common ancestor path.


[System] You are a helpful assistant.

[User]
Continue working on a Git branch after making a pull request

I've found myself in this situation a couple of times lately, and I'm not totally sure how best to handle it.
So I have a fork of a git repository that I'm contributing to. I keep my master branch synced with the upstream master branch.
When I want to work on a new feature, bugfix, etc, I create a branch from my master and do any work. When I'm done, I merge in any changes that have been made to upstream master in the meantime, and then send a pull request from my feature/bugfix branch to the upstream master.
Now, while I'm waiting for that pull request to be accepted, I want to work on something slightly different. However, the new feature work needs the bugfix/new feature that I just sent the pull request for. I need to build on it.
How do I branch/merge/handle branches in such a way that I can work on the continuation, while still being able to merge/pull request in my changes in a clean way once the first pull request is accepted into master?
This is all using Github, although I imagine the answer would be applicable to Git in general.

[Assistant]
Create a new branch feature2 based on the last commit to feature1. feature1 will not move forward any more, and can be merged.
feature2 can then be merged later (some people would argue to rebase feature2 on the commit where feature1 was merged into upstream, but personally i dislike rebasing).


[System] You are a helpful assistant.

[User]
Git and SSH, which key is used?
Say your .ssh directory contains 30 keys (15 private and 15 public).
Where in Git can one check which one is used to connect to a given remote repository?

[Assistant]
The following entry in .ssh/config file solves the problem
  host git.assembla.com
  user git
  identityfile ~/.ssh/whatever

Where ~/.ssh/whatever is a path to your private key
Additionally, user and host can be picked up from
git push [email protected]:repo_name.git
         ^__ ^_______________
         user host


[System] You are a helpful assistant.

[User]
git status returns fatal: Not a git repository but .git exists and HEAD has proper permissions
When I run git status on my repo I get fatal: Not a git repository: /my repo/.git/modules/docs
I've checked and .git exists and contains HEAD with the proper permissions. I can run various other commands fine. If I run git gui it opens fine and will list a couple of the changed files, but is missing a lot of them.
I'm guessing there may be some sort of corruption in HEAD, not sure though. Any idea how to fix this without wiping out the whole repo?
Update: I realized that I had changed the name of the repo's directory. The directory being referenced in the error is the old name of the directory. So my current repo is at /new dir/.git but the error is saying Not a git repository: /old dir/.git/modules/docs. So maybe git is confused?

[Assistant]
These two files contains absolute submodule path:
{submodule}/.git
.git/modules/{submodule}/config

So, if you moved the repo, the absolute path in these two files are not valid, and cause the 'not a git repository' error. Just fix these files manually.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  transfer.fsckObjects

[Assistant]
When fetch.fsckObjects or receive.fsckObjects are
not set, the value of this variable is used instead.
Defaults to false. When set, the fetch or receive will abort in the case of a malformed
object or a link to a nonexistent object. In addition, various other
issues are checked for, including legacy issues (see fsck.<msg-id> ),
and potential security issues like the existence of a .GIT directory
or a malicious .gitmodules file (see the release notes for v2.2.1
and v2.17.1 for details). Other sanity and security checks may be
added in future releases. On the receiving side, failing fsckObjects will make those objects
unreachable, see "QUARANTINE ENVIRONMENT" in git-receive-pack . On the fetch side, malformed objects will
instead be left unreferenced in the repository. Due to the non-quarantine nature of the fetch.fsckObjects implementation it cannot be relied upon to leave the object store
clean like receive.fsckObjects can. As objects are unpacked they’re written to the object store, so there
can be cases where malicious objects get introduced even though the
"fetch" failed, only to have a subsequent "fetch" succeed because only
new incoming objects are checked, not those that have already been
written to the object store. That difference in behavior should not be
relied upon. In the future, such objects may be quarantined for
"fetch" as well. For now, the paranoid need to find some way to emulate the quarantine
environment if they’d like the same protection as "push". E.g. in the
case of an internal mirror do the mirroring in two steps, one to fetch
the untrusted objects, and then do a second "push" (which will use the
quarantine) to another internal repo, and have internal clients
consume this pushed-to repository, or embargo internal fetches and
only allow them once a full "fsck" has run (and no new fetches have
happened in the meantime).


[System] You are a helpful assistant.

[User]
Git: How to rebase to a specific commit?
I'd like to rebase to a specific commit, not to a HEAD of the other branch:
A --- B --- C          master
 \
  \-- D                topic

to
A --- B --- C          master
       \
        \-- D          topic

instead of
A --- B --- C          master
             \
              \-- D    topic

How can I achieve that?

[Assistant]
You can avoid using the --onto parameter by making a temp branch on the commit you like and then use rebase in its simple form:
git branch temp master^
git checkout topic
git rebase temp
git branch -d temp


[System] You are a helpful assistant.

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

[Assistant] author email local-part (the part before the @ sign)


[System] You are a helpful assistant.

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

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


[System] You are a helpful assistant.

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

[Assistant] left ( < ), right ( > ) or boundary ( - ) mark


[System] You are a helpful assistant.

[User]
Transfer gist repo to github
I am working on a small project with gist and since it is growing I would like to put it on github.
Let's suppose that:

my gist repo is at: https://gist.github.com/1234
my new (empty) repo is at: https://github.com/ChrisJamesC/myNewProject

The ideal solution would be one that pushes my changes on both the gist and the github repository.

[Assistant]
You can add the github repository as a remote to your checked out gist repository.
git clone [email protected]:1234.git
git remote add github [email protected]:ChrisJamesC/myNewProject.git

Push it to initialize the git on github
git push -u github master

If your github repo wasn't quite empty (you created it with a README, license, etc. which you don't mind losing) you will have to do a force overwrite on your push
git push -f -u github master

If you don't want to lose the exiting commits and files, see https://stackoverflow.com/a/40408059/117471

This will also change the upstream of the branch, so github will be default.
You now can rename the remote of gist:
git remote rename origin gist

Each time you make changes (or pull changes from github/gist), you can do:
git push                 # To github
git push gist master     # To gist

This will also push back your changes to the gist and not only the github repo.


[System] You are a helpful assistant.

[User]
How to clone git repository from its zip
I'm trying to clone a remote repository on github, but it is big and my connection doesn't seem to be stable enough, so I can't clone it successfully.
But I have successfully downloaded the .zip of the repository.
Is there a way to use this zip as it was created by git clone, so I can push, pull etc..?

[Assistant]
A related post here provides the information needed to grab the .git directory and simplify the answer that umläute provided:

Grab the .git directory by cloning a bare repository
$ mkdir repo
$ git clone --bare http://github/user/repo repo

Make the .git directory and move the cloned files
$ mkdir repo/.git
$ mv repo/* repo/.git

Unzip the repository
$ unzip repo.zip

Re-initialize the repository
$ cd repo
$ git init

Verify you're sync'ed
$ git pull

Reset the HEAD to clean up the status
$ git reset HEAD

Here's the log for the repo ... repo location - http://github.com/udacity/fullstack-nanodegree-vm
$ git log
commit ebcbda650bc81d7f4856f5314a0689cea5b43086
Merge: 574774b b5b787e
Author: Karl Krueger <[email protected]>
Date:   Tue Apr 7 11:39:54 2015 -0700`

        Merge pull request #3 from pmallory/sharedDirAlert

        Add a login alert to explain how to access Vagrant's shared directory

commit b5b787efdb1ecec0c3c9c7f9c0fd4732f984fcb3
Author: Philip Mallory <[email protected]>
Date:   Mon Apr 6 15:40:32 2015 -0700`

       move the alert into the motd

commit b8012f33c86b0d19fc4c2b972af092e88d00978f
Author: Philip Mallory <[email protected]>
Date:   Mon Apr 6 14:32:01 2015 -0700`

       Add a login alert to explain how to access Vagrant's shared directory

commit 574774ba29ccd661154431d5600240f090440c37
Author: Lorenzo Brown <[email protected]>
Date:   Wed Mar 11 14:08:02 2015 -0700`

       Update pg_config.sh

       Added installs for Auth&Auth

commit 88fc5537b1a0017a1d76af4587a22412473809a4
Author: Lorenzo Brown <[email protected]>
Date:   Wed Mar 4 13:00:25 2015 -0800`

       Update and rename vagrant to vagrant/catalog/README.txt

commit f978cdc14c62b7295d8da1a95452faaa1bd108b8
Author: Lorenzo Brown <[email protected]>
Date:   Wed Feb 4 11:06:03 2015 -0800`

       Update Vagrantfile

       switched to port forwarding on 8080

commit d6a3a26578ef3c6d01d28abca76d817938892c7f
Author: Lorenzo Brown <[email protected]>
Date:   Tue Feb 3 14:52:34 2015 -0800`

       Update Vagrantfile

       Added:

       config.vm.network "forwarded_port", guest: 80, host: 8080
       config.vm.network "forwarded_port", guest: 5000, host: 5000

       FSF uses these two ports for lessons 2 & 3 respectively.

commit 752a79e408c7328ef7f1766d1b97bb468ffed90a
Author: Mike Wales <[email protected]>
Date:   Mon Feb 2 11:21:29 2015 -0800`

       Removed .vagrant directory

commit 5af9d19adf9ab19b1d886f6cc78e556f864b42dd
Author: Mike Wales <[email protected]>
Date:   Mon Feb 2 11:16:45 2015 -0800`

       Initial commit.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --exclude-hidden=[fetch|receive|uploadpack]

[Assistant] Do not include refs that would be hidden by git-fetch , git-receive-pack or git-upload-pack by consulting the appropriate fetch.hideRefs , receive.hideRefs or uploadpack.hideRefs configuration along with transfer.hideRefs (see git-config ). This option affects the next pseudo-ref option --all or --glob and is cleared after processing them.


[System] You are a helpful assistant.

[User] git-rev-parse - Pick out and massage parameters  --symbolic

[Assistant]
Usually the object names are output in SHA-1 form (with
possible ^ prefix); this option makes them output in a
form as close to the original input as possible.


[System] You are a helpful assistant.

[User]
Restore a file's modification time in Git
I understand the default Git behaviour of updating the modification time every time it changes a file, but there are times when I want to restore a file's original modification time.
Is there a way I can tell Git to do this?
(As an example, when working on a large project, I made some changes to configure.ac, found out that autotools doesn't work on my system, and wanted to restore configure.ac's to its original contents and modification time so that make doesn't try to update configure with my broken autotools.)

[Assistant]
Restore the modificaton time of a list of files to the author date of the their last commit with
gitmtim(){ local f;for f;do touch -d @0`git log --pretty=%at -n1 -- "$f"` "$f"; done;}; gitmtim configure.ac

It will not change directories recursively, though.
If you want to change a whole working tree, e.g. after a fresh clone or checkout, you may try
git log --pretty=%at --name-status --reverse | perl -ane '($x,$f)=@F;next if !$x;$t=$x,next if !defined($f)||$s{$f};$s{$f}=utime($t,$t,$f),next if $x=~/[AM]/;'

NB: I grepped for utime in builtin/clone.c and got no matches.


[System] You are a helpful assistant.

[User]
Does NPM ignore files listed in .gitignore?
I have a file that is generated by npm install command (using preinstall task). I don't want to add it in the git repository, nor in the NPM project.
Supposing the file name is foo.json, I added it in .gitignore file as foo.json.
Is this enough to avoid uploading it on NPM registry?
I know I can add .npmignore file that will surely ignore the file, but I won't add it if .gitignore already does this.

[Assistant]
If a project has both .npmignore and .gitignore, npm will only use the .npmignore file.
From the documentation:

Use a .npmignore file to keep stuff out of your package. If there's no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file. If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it.

In simpler terms, npm prefers the .npmignore file, but it will fall back to the .gitignore file.
In many cases, both Git and npm can ignore the same files, so it makes sense to just use a .gitignore file.
If you need npm and Git to ignore different files, then you need to maintain separate .gitignore and .npmignore files.
More information on what to put in .npmignore files: Should I .npmignore my tests?


[System] You are a helpful assistant.

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

[Assistant] Join two or more development histories together


[System] You are a helpful assistant.

[User]
How do I prevent an automerge using Git?
I am trying to merge a local branch into the master branch without having Git to do an automerge. I would like to “hand pick” what I would like to be merged into master.
When I use Git’s difftool command, I am able to diff and select what I want to be added into the master branch. But then when I do a merge, I will lose what I selected prior because Git will do an automerge. I can commit the changes into master prior to the merge, but doing so seems unnatural.
And Git’s mergetool is only available when there are conflicts from a merge. But if Git does an automerge then usually there aren’t conflicts, so I am unable to run the mergetool command.
Update:
I am starting to think what I am trying to accomplish is bad practice or it’s just not possible. That is, to merge a topic branch and only have it merge what I need from diffing. And in an addition, to have this reflected in history. At any rate, the question I posted surfaced when experimenting with Git.

[Assistant]
You are trying to bypass Git from getting involved in the merge process and to hand-pick each line of each modified file to be merged. This not the same as git cherry-pick. Neither will git merge --no-commit, etc. help. You will need to do:
$ git checkout master
$ git difftool -t kdiff3 local-branch HEAD

In the KDiff3 window, the left hand side (A) is your local-branch and the right hand side (B) is your current branch (master).
Select Merge | Merge Current File from the menu (or press the colorful diamond shaped icon with the same title).
You will then be shown a diff and conflicts (if any) for each file. And you will have the ability to pick left or right side (A or B), or both, and/or manually tweak the merged file.
On another note, something is telling me you have some bigger issues with your workflow.


[System] You are a helpful assistant.

[User]
Visual Studio Code - Connect to a remote Git repository and PUSH local files to a new remote repository
I have created a local project with Visual Studio Code that implements a local Git repository.
Then I have create a Git repository on Visual Studio Online and I want to push all my project files to the remote repository...
What is the correct procedure to do it?
My .git\config files at this moment look like this:
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true

[Assistant]
I assume you started to work in a directory and didn't use Git there. The following should work with Git Bash:
cd "path to your repository"
git init
git add . # If you want to commit everything. Otherwise use .gitconfig files
git commit -m "initial commit" # If you change anything, you can add and commit again...

To add a remote, just do
git remote add origin https://...
git remote show origin # If everything is ok, you will see your remote
git push -u origin master # Assuming you are on the master branch.

The -u sets an upstream reference and Git knows from where to fetch/pull and where to push in the future.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  GIT_COMMITTER_DATE

[Assistant]
The date used for the committer identity when creating commit or tag objects, or
when writing reflogs. See git-commit for valid formats.


[System] You are a helpful assistant.

[User]
Listing and deleting Git commits that are under no branch (dangling?)
I've got a Git repository with plenty of commits that are under no particular branch, I can git show them, but when I try to list branches that contain them, it reports back nothing.
I thought this is the dangling commits/tree issue (as a result of -D branch), so I pruned the repo, but I still see the same behavior after that:
$ git fetch origin

$ git fsck --unreachable
$ git fsck

No output, nothing dangling (right?). But the commit exists
$ git show 793db7f272ba4bbdd1e32f14410a52a412667042
commit 793db7f272ba4bbdd1e32f14410a52a412667042
Author: ...

and it is not reachable through any branch as
$ git branch --contains 793db7f272ba4bbdd1e32f14410a52a412667042

gives no output.
What exactly is the state of that commit? How can I list all commits in a similar state? How can I delete commits like those?

[Assistant]
To remove all dangling commits (including those still reachable from stashes and other reflogs) do this:
git reflog expire --expire-unreachable=now --all
git gc --prune=now

But be certain that this is what you want. I recommend you read the man pages but here is the gist:
git gc removes unreachable objects (commits, trees, blobs (files)). An object is unreachable if it isn't part of the history of some branch. Actually it is a bit more complicated:
Stashes are implemented using the reflog (i.e not not branches or tags). That means that they are subject to garbage collection. Or, to make it more explicit: running the above commands will delete all your stashes.
git gc does some other things but they are not relevant here and not dangerous.
Unreachable objects that are younger than two weeks are not removed so we use --prune=now which means "remove unreachable objects that were created before now".
Objects can also be reached through the reflog. While branches record the history of some project, reflogs record the history of these branches. If you amend, reset etc. commits are removed from the branch history but git keeps them around in case you realize that you made a mistake. Reflogs are a convenient way to find out what destructive (and other) operations were performed on a branch (or HEAD), making it easier to undo a destructive operation.
So we also have to remove the reflogs to actually remove everything not reachable from a branch. We do so by expiring --all reflogs. Again git keeps a bit of the reflogs to protect users so we again have to tell it not to do so: --expire-unreachable=now.
Since I mainly use the reflog to recover from destructive operations I usually use --expire=now instead, which zaps the reflogs completely.


[System] You are a helpful assistant.

[User]
Git diff - how to quit the diff listing [duplicate]
This question already has answers here:

How to exit a 'git status' list in a terminal?

                                (17 answers)

Closed 8 years ago.

How do you quit git diff listing?
There is an <END> marker at the bottom of the screen, and everything I do which appears to quit the diff listing, then shows an <END> marker at the bottom of the screen again.

[Assistant] The default pager for git is less. To quit less, hit q.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  add.ignoreErrors  add.ignore-errors (deprecated)

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


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  transfer.hideRefs

[Assistant]
String(s) receive-pack and upload-pack use to decide which
refs to omit from their initial advertisements.  Use more than
one definition to specify multiple prefix strings. A ref that is
under the hierarchies listed in the value of this variable is
excluded, and is hidden when responding to git push or git
fetch .  See receive.hideRefs and uploadpack.hideRefs for
program-specific versions of this config. You may also include a ! in front of the ref name to negate the entry,
explicitly exposing it, even if an earlier entry marked it as hidden.
If you have multiple hideRefs values, later entries override earlier ones
(and entries in more-specific config files override less-specific ones). If a namespace is in use, the namespace prefix is stripped from each
reference before it is matched against transfer.hiderefs patterns. In
order to match refs before stripping, add a ^ in front of the ref name. If
you combine ! and ^ , ! must be specified first. For example, if refs/heads/master is specified in transfer.hideRefs and
the current namespace is foo , then refs/namespaces/foo/refs/heads/master is omitted from the advertisements. If uploadpack.allowRefInWant is set, upload-pack will treat want-ref refs/heads/master in a protocol v2 fetch command as if refs/namespaces/foo/refs/heads/master did not exist. receive-pack , on the other hand, will still advertise the object id the
ref is pointing to without mentioning its name (a so-called ".have" line). Even if you hide refs, a client may still be able to steal the target
objects via the techniques described in the "SECURITY" section of the gitnamespaces man page; it’s best to keep private data in a
separate repository.


[System] You are a helpful assistant.

[User]
Getting existing git branches to track remote branches
My usual workflow when working with git, is something like this:

create a local repository
do some work in that repository, add/change files etc.
decide that I want a central remote location for the repository, and create one
push all the commits from my local repository to this new remote repository

Now, however, I want to be able to push and pull from this remote repository without having to specify where I'm pushing to or pulling from; I want my local master to track the remote master.
The proper way to do this isn't clear to me, and I've been unable to determine it from the documentation, even though it shouldn't really be more than one command.
Because it's something that's only ever done once per repository, I've generally employed one of two simple, but hacky, solutions:

used git clone to make a new local repository, and deleted the old one. After git cloning, the new repository is setup to track the origin.
manually edited .git/config to make master track origin.

I think I should be able to run a command, probably some form of git remote to setup an existing repository to have master track a remote master. Can anyone tell me what that command is?

[Assistant]
Use the set-upstream arg:
git branch --set-upstream local-branch-name origin/remote-branch-name

Running the above command updates your .git/config file correctly and even verifies with this output:
"Branch local-branch-name set up to track remote branch remote-branch-name from origin."
EDIT: As martijn said: "In version Git v1.8.0, --set-upstream is deprecated. Use --set-upstream-to instead."
git branch --set-upstream-to local-branch-name origin/remote-branch-name

See this for more information.


[System] You are a helpful assistant.

[User]
Git: Could not resolve host github.com error while cloning remote repository in git
What I did: I have created a remote repository on Github and I am trying to clone the remote repository on my local machine. While cloning I am providing the clone URL & target folder.
But every time I try to clone, I am getting this error:
Error: "fatal: unable to access 'https://github.com/hyperion057/spring-repo.git/': Could not resolve host: github.com"
What do I need to do to connect to GitHub ?

[Assistant]
I got a similar error, and it's caused by incorrect proxy setting. This command saved me:
git config --global --unset http.proxy

https version:
git config --global --unset https.proxy


[System] You are a helpful assistant.

[User] git-rev-parse - Pick out and massage parameters  --not

[Assistant]
When showing object names, prefix them with ^ and
strip ^ prefix from the object names that already have
one.


[System] You are a helpful assistant.

[User]
How to resume review process after updating pull request at GitHub?
I forked GitHub repository and created pull request. Reviewer requested changes from me:

Changes requested
1 review requesting changes by reviewers with write access. Learn more.

I've committed and pushed necessary changes in pull request branch, so they are displaying at pull request page. Now I want ask contributor to continue review my changes.
Is there any button or action for this? Can't find this.

[Assistant]
2 years and a half years later, (February 2019), do check if the new button "Re-request review" would help.
As illustrated on twitter, if your PR was already reviewed, but now it’s time for round 2: With fresh eyes and fresh code, re-request a review 🔃

Note/caveat: (from "Requesting a pull request review")

Pull request authors can't request reviews unless they are either a repository owner or collaborator with write access to the repository.

As noted in the comments by gertvdijk:

I am a contributor on the project and the owner of the PR.
  It does not make sense to me that I need to be a collaborator on the project to request a re-review?
Oh, wow, it's by design that PR authors can't use this feature?
  Damn, that's very much killing the whole feature.


[System] You are a helpful assistant.

[User]
Yarn can't find private Github npm registry

I signed up for the Github private npm registry beta and followed their instruction: https://github.com/features/package-registry
Works great with npm but I'd prefer using yarn. And while npm has no issues finding the registered package, yarn can't find it at all.
yarn add @omniphx/adminite-adminite-ui-components outputs:
yarn add v1.19.0
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
error Couldn't find package "@omniphx/adminite-ui-components" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

After reading up on private repos with yarn, I thought the trick was due to yarn having a slightly different rc format. Unfortunately, that didn't work either and yarn is still unable to find the private registry.
.npmrc
registry=https://registry.npmjs.org
@omniphx:registry=https://npm.pkg.github.com/omniphx

.yarnrc
registry "https://registry.npmjs.org"
"@omniphx:registry" "https://npm.pkg.github.com/omniphx"

Also confirmed that my github token is set too with yarn config list:
yarn config v1.19.0
info yarn config
{
  'version-tag-prefix': 'v',
  'version-git-tag': true,
  'version-commit-hooks': true,
  'version-git-sign': false,
  'version-git-message': 'v%s',
  'init-version': '1.0.0',
  'init-license': 'MIT',
  'save-prefix': '^',
  'bin-links': true,
  'ignore-scripts': false,
  'ignore-optional': false,
  registry: 'https://registry.npmjs.org',
  'strict-ssl': true,
  'user-agent': 'yarn/1.19.0 npm/? node/v12.11.1 darwin x64',
  email: '[email protected]',
  lastUpdateCheck: 1570679687836,
  username: 'omniphx',
  '@omniphx:registry': 'https://npm.pkg.github.com/omniphx'
}
info npm config
{
  '//npm.pkg.github.com/:_authToken': 'fake12345',
  registry: 'https://registry.npmjs.org',
  '@omniphx:registry': 'https://npm.pkg.github.com/omniphx',
  python: '/usr/bin/python'
}

Any idea?

Resolved
Changed "@myorg:registry" "https://npm.pkg.github.com/myorg"
To      "@myorg:registry" "https://npm.pkg.github.com"

[Assistant]
I've just run into a similar situation. It seemed that yarn was only looking in the main Yarn package registry for my organization's private package. I had copied the examples from GitHub's Packages documentation for constructing your .npmrc file directly to the .yarnrc file in the project that will be consuming the app, not knowing that the formats were different (I've never had to deal with .yarnrc files before).
However, after updating the .yarnrc file with the correct format that you've mentioned above (which I also found in googling around), yarn successfully found the private package and installed it correctly.
As a heads up, my yarn version: 1.17.3
Steps I Took

Start new terminal session
cd to the project
nvm use (if you have a specific node version to use)
Add the correctly-formatted .yarnrc file to the project. See below for what it looks like.
Manually add the package and version range to the package.json for my private package
Run npm login --registry=https://npm.pkg.github.com --scope=@MyOrg

See the note below on scope / org gotcha's

Run yarn

That worked for me.
.yarnrc
"@myorg:registry" "https://npm.pkg.github.com"

Note: See below for a note on the org / scope name gotcha's
Other Notes
I know that it appears that you don't have any issues with this, given your GH username / scope above, but for anyone else that comes here, the documentation on GH is a little sparse with regards to mapping your username / org name to a scope in the package name. Just remember these little gotcha's here:

The name of your package must always be scoped to your org (or username)

E.g., name: @johndturn/my-package

If your organization has capital letters in it, like MyOrg, just replace them in the name of the package in your package.json and your .yarnrc with lowercase

E.g., name: @myorg/my-package
Note: When authenticating with npm login, I still have kept the uppercase letters in the --scope= argument.

The name of your package doesn't have to be the same name of the repo.

E.g., for a repo called MyOrg/random-prefix.js-lib, you can have name: @myorg/js-lib in your package.json file for the project itself. Then, installing it in other projects will look something like @myorg/js-lib: 1.0.0.


[System] You are a helpful assistant.

[User]
executing a git pull from a different directory
I'm configuring calimoucho (a little play continuos integration server), and for it to work I need to run a command to pull a cloned git hub repository from outside it.
to be more precise, I'll explain it with an example.
I have the following repository
cd /home/sas
mkdir apps
cd apps
mkdir myApp
cd myApp
git init
echo "my file" > file
git add .
git commit -m "initial commit"

Just a silly test repository where my app is supossed to be
Now I need to clone that repository to a checkout folder.
cd /home/sas
mkdir calimoucho
cd calimoucho
mkdir checkout
cd checkout
git clone /home/sas/apps/myApp/

so I have the following directory structure
~/apps
    myapp
      .git
      file
~/calimoucho
    checkout
      myapp
        .git
        file

The continuos integration server will have to pull new changes from ~/apps/myapp to ~/calimoucho/checkout/myapp, running a command line sentence from ~/calimoucho
I try with the following command
~/calimoucho$ git --git-dir=/home/sas/apps/myApp/.git --work-tree=/home/sas/calimoucho/checkout/myApp/ pull

and I get the following error
fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.

if I don't specify the --work-tree option, the pull is issued, but changes are applied to ~/calimoucho folder instead of ~/calimoucho/checkout/myApp
any idea how to update the cloned repo from the ~/calimoucho folder?
thanks a lot

[Assistant]
I had this question, too.  I found the answer in the git documentation (https://git-scm.com/docs/git).
Run the command
git -C <git-working-directory> pull <git remote>

The specific command to answer this question is
git -C checkout/myApp/ pull

Note that it is important -C <git-working-directory> comes before the pull command and any additional pull options can be specified at the end of the command.  In the example above, the git clone command would have setup the default remote repository ~/apps/myapp so it is not required to specify the remote repository.


[System] You are a helpful assistant.

[User]
E325: ATTENTION Found a swap file by the name ".git/.COMMIT_EDITMSG.swp"

I've been working with a team for almost a year now. It's always been easy to use github/git to pull and push changes using:
git pull
git add .
git commit -a -m "my work desc"
git push

That has always worked fine until recently. Now no matter what, if someone else has pushed, whenever I try to pull I get this message:
E325: ATTENTION
Found a swap file by the name ".git/.COMMIT_EDITMSG.swp"
          owned by: X   dated: Wed Jan 23 16:01:06 2013
         file name: ~X/Sites/mysite/.git/COMMIT_EDITMSG
          modified: no
         user name: X   host name: X-2.local
        process ID: 77109
While opening file ".git/COMMIT_EDITMSG"
             dated: Thu Jan 24 16:22:48 2013
      NEWER than swap file!

(1) Another program may be editing the same file.
    If this is the case, be careful not to end up with two
    different instances of the same file when making changes.
    Quit, or continue with caution.

(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r .git/COMMIT_EDITMSG"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".git/.COMMIT_EDITMSG.swp"
    to avoid this message.

Swap file ".git/.COMMIT_EDITMSG.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

This happens every time w/o fail. I can eventually get past this by inserting a message, saving and recommitting but it's a pain. Any idea why this keeps happening and what can be done?
Thanks

[Assistant]
Unless you need .git/.COMMIT_EDITMSG.swp for some other purpose, you can use:
git rm .git/.COMMIT_EDITMSG.swp

to remove the file from the repository.


[System] You are a helpful assistant.

[User] git-ls-tree - List the contents of a tree object  --full-name

[Assistant]
Instead of showing the path names relative to the current working
directory, show the full path names.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  pack.preferBitmapTips

[Assistant]
When selecting which commits will receive bitmaps, prefer a
commit at the tip of any reference that is a suffix of any value
of this configuration over any other commits in the "selection
window". Note that setting this configuration to refs/foo does not mean that
the commits at the tips of refs/foo/bar and refs/foo/baz will
necessarily be selected. This is because commits are selected for
bitmaps from within a series of windows of variable length. If a commit at the tip of any reference which is a suffix of any value
of this configuration is seen in a window, it is immediately given
preference over any other commit in that window.


[System] You are a helpful assistant.

[User] git-commit-tree - Create a new commit object

[Assistant] NAME git-commit-tree - Create a new commit object


[System] You are a helpful assistant.

[User]
Project vs Repository in GitHub

In GitHub, what is the conceptual difference between a project (that can be created inside a repository) and a repository?
I've seen several similar questions (here, here and here) in SO, but none of them explains what is a GitHub project, what is a GitHub repository and when to use each one of them.
I would appreciate if someone can explain each term, and provide an example of when to use/create each one. For instance, if I have several prototype applications, all independent of each other, what do I create in order to manage in an organized way the source code for all of them?

[Assistant]
Fact 1: Projects and Repositories were always synonyms on GitHub.Fact 2: This is no longer the case.
There is a lot of confusion about Repositories and Projects. In the past both terms were used pretty much interchangeably by the users and the GitHub's very own documentation. This is reflected by some of the answers and comments here that explain the subtle differences between those terms and when the one was preferred over the other. The difference were always subtle, e.g. like the issue tracker being part of the project but not part of the repository which might be thought of as a strictly git thing etc.
Not any more.
Currently repos and projects refer to a different kinds of entities that have separate APIs:

https://developer.github.com/v3/repos/
https://developer.github.com/v3/projects/

Since then it is no longer correct to call the repo a project or vice versa.
Note that it is often confused in the official documentation and it is unfortunate that a term that was already widely used has been chosen as the name of the new entity but this is the case and we have to live with that.
The consequence is that repos and projects are usually confused and every time you read about GitHub projects you have to wonder if it's really about the projects or about repos. Had they chosen some other name or an abbreviation like "proj" then we could know that what is discussed is the new type of entity, a precise object with concrete properties, or a general speaking repo-like projectish kind of thingy.
The term that is usually unambiguous is "project board".
What can we learn from the API
The first endpoint in the documentation of the Projects API:

https://developer.github.com/v3/projects/#list-repository-projects

is described as: List repository projects. It means that a repository can have many projects. So those two cannot mean the same thing. It includes Response if projects are disabled:
{
  "message": "Projects are disabled for this repo",
  "documentation_url": "https://developer.github.com/v3"
}

which means that some repos can have projects disabled. Again, those cannot be the same thing when a repo can have projects disabled.
There are some other interesting endpoints:

Create a repository project - POST /repos/:owner/:repo/projects
Create an organization project - POST /orgs/:org/projects

but there is no:

Create a user's project - POST /users/:user/projects

Which leads us to another difference:
1. Repositories can belong to users or organizations2. Projects can belong to repositories or organizations
or, more importantly:
1. Projects can belong to repositories but not the other way around2. Projects can belong to organizations but not to users3. Repositories can belong to organizations and to users
See also:

https://help.github.com/articles/about-project-boards/

I know it's confusing. I tried to explain it as precisely as I could.


[System] You are a helpful assistant.

[User]
git push vs git push origin <branchname>
I'm quite new to Git.
I'm creating a branch and then want to push it to origin.
I think that simply issuing git push (while standing on my branch) should be sufficient.
Is it possible/reasonable to do that (by specifying push.default simple)?

[Assistant]
The first push should be a:
git push -u origin branchname

That would make sure:

your local branch has a remote tracking branch of the same name referring an upstream branch in your remote repo 'origin',
this is compliant with the default push policy 'simple'

Any future git push will, with that default policy, only push the current branch, and only if that branch has an upstream branch with the same name.
that avoid pushing all matching branches (previous default policy), where tons of test branches were pushed even though they aren't ready to be visible on the upstream repo.


[System] You are a helpful assistant.

[User]
Handling renames: svn vs. git vs. mercurial
How do each of these VCS handle renames?
I have found a lot of contradicting information stating that git tracks LOC (lines of code) instead of files, renames would therefore have no meaning for it.

[Assistant]
Git doesn't track renames at all, but uses heuristic to re-discover them during merge etc.
Mercurial tracks renames (the origin version and origin file is recorded) and uses that information during merges. So you have to explicitly tell hg about renames with hg mv, or use hg addremove --similarity for auto-discovery. There has been some talk about adding heuristics during merge too.
Svn tracks renames, but I don't know how good it deals with them during merges (never actually tested that).


[System] You are a helpful assistant.

[User]
Git error fatal: unable to stat '*': No such file or directory
I ran into this error, and found very little documentation on how to fix it online. I got the error by trying to run the command git add ., and received this response:
fatal: unable to stat 'myPathToAFile': No such file or directory

[Assistant]
To solve the problem, I removed the file from git, then re-added it by doing the following:
git rm "myPathToAFile"
git add .
git commit -am 'my commit'
Hope this helps someone else!


[System] You are a helpful assistant.

[User] git-range-diff - Compare two commit ranges (e.g. two versions of a branch)  <base> <rev1> <rev2>

[Assistant]
Equivalent to passing <base>..<rev1> and <base>..<rev2> .
Note that <base> does not need to be the exact branch point
of the branches. Example: after rebasing a branch my-topic , git range-diff my-topic@{u} my-topic@{1} my-topic would
show the differences introduced by the rebase.


[System] You are a helpful assistant.

[User]
.gitignore for visual studio project is not working
I am using standard Visual Studio .gitignore file, but Git for Windows still includes build files and other stuff. How to fix this?
Git ignore file I am using: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
Visual Studio generates the same thing automatically
It is named correctly, and it is in the right place

When I enter git status command it shows build files

[Assistant]
To stop tracking the files in the gitignore file;
Open a command prompt and navigate to the directory that contains your solution file (.sln), then run the following commands (first two commands contains dot at last):

Remove all of the items from the Git index (not from the working directory or local repository):

    git rm -r --cached .

Update the Git index according to gitignore:

    git add .

Commit changes:

    git commit -am "Remove ignored files"

Then open your Visual Studio and sync your repo.
That seemed to do the trick for me.  I found the git commands here.


[System] You are a helpful assistant.

[User]
Multi-user Github Pull Requests

Is it possible to amend a pull request that someone else has started?
Assume I maintain project X, and User A has sent me a pull request.  There's some things I want changed before merging and can quickly do them myself.  How can I do this simply and keep it all within one PR?
Is this even possible?

[Assistant]
You can do it like this:
In your repo,
git checkout -b new-branch

Then pull User A's commits into your new-branch:
git pull git://github.com/[User A]/[project-name].git

After that, you can change it whatever you like in the new-branch. And when you test and satisfy with your changes, you can merge it into your master branch:
git checkout master
git merge new-branch

OK, now you have your code with User A and your changes.


[System] You are a helpful assistant.

[User]
How to apply a git patch when given a pull number

I downloaded a trunk version of a codebase from git, and there are build errors. Aparently a patch is now available, and I received an email :
see https://github.com/JustinTulloss/zeromq.node/pull/47 for patch
I am new to git so I'm not quite sure what to do with this 'patch' especially, since the page looks more like a discussion thread.
Does anyone know how I can obtain/apply this patch to my locally cloned git repository?

[Assistant]
Save the patch somewhere. If you're using linux you can use curl:
curl -L https://github.com/JustinTulloss/zeromq.node/pull/47.patch > /tmp/47.patch

To apply the patch use git apply. You can see if the patch will apply cleanly with the check option. Change to your git directory and run:
git apply --check /tmp/47.patch

If it looks like you want to apply the patch remove the check option
git apply /tmp/47.patch


[System] You are a helpful assistant.

[User]
How to solve Access denied in gitlab?

When I run : git push, there is exist error like this :
remote: Access denied
fatal: unable to access 'https://gitlab.com/myname/mysystem.git/': The requested URL returned error: 403

Is there any people who can help me?

[Assistant]
For Windows users, check this unbelievable easy solution, which works for me:
Go to Windows Credential Manager (press Windows Key and type 'credential') to edit the git entry under Windows Credentials. Replace old password with the new one.


[System] You are a helpful assistant.

[User]
Git is not detecting a file and is not in .gitignore
I have a file called "style.css" and git is not detecting it. It doesn't detect it if I delete it either, but it does detect if I change the name of the file. But I need it with that name.
The file is not in the .gitignore file. This is driving me crazy!
I would appreciate some help.

[Assistant]
Use git check-ignore command to debug your gitignore file (exclude files).
In example:
$ git check-ignore -v config.php
.gitignore:2:src    config.php

The above output details about the matching pattern (if any) for each given pathname (including line).
So maybe your file extension is not ignored, but the whole directory.
The returned format is:
<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

Or use the following command to print your .gitignore in user and repo folder:
cat ~/.gitignore $(git rev-parse --show-toplevel)/.gitignore $(git rev-parse --show-toplevel)/.git/info/exclude

Alternatively use git add -f <path/file> which allows adding otherwise ignored files.
See: man gitignore, man git-check-ignore for more details.


[System] You are a helpful assistant.

[User]
How to push different local Git branches to Heroku/master
Heroku has a policy of ignoring all branches but 'master'.
While I'm sure Heroku's designers have excellent reasons for this policy (I'm guessing for storage and performance optimization), the consequence to me as a developer is that whatever local topic branch I may be working on, I would like an easy way to switch Heroku's master to that local topic branch and do a "git push heroku -f" to over-write master on Heroku.
What I got from reading the "Pushing Refspecs" section of http://progit.org/book/ch9-5.html is
git push -f heroku local-topic-branch:refs/heads/master
What I'd really like is a way to set this up in the configuration file so that "git push heroku" always does the above, replacing local-topic-branch with the name of whatever my current branch happens to be.  If anyone knows how to accomplish that, please let me know!
The caveat for this, of course, is that this is only sensible if I am the only one who can push to that Heroku app/repository. A test or QA team might manage such a repository to try out different candidate branches, but they would have to coordinate so that they all agree on what branch they are pushing to it on any given day.
Needless to say, it would also be a very good idea to have a separate remote repository (like GitHub) without this restriction for backing everything up to. I'd call that one "origin" and use "heroku" for Heroku so that "git push" always backs up everything to origin, and "git push heroku" pushes whatever branch I'm currently on to Heroku's master branch, overwriting it if necessary.
Would this work?

[remote "heroku"]
    url = [email protected]:my-app.git
    push = +refs/heads/*:refs/heads/master

I'd like to hear from someone more experienced before I begin to experiment, although I suppose I could create a dummy app on Heroku and experiment with that.
As for fetching, I don't really care if the Heroku repository is write-only. I still have a separate repository, like GitHub, for backup and cloning of all my work.
Footnote: This question is similar to, but not quite the same as Good Git deployment using branches strategy with Heroku?

[Assistant]
See https://devcenter.heroku.com/articles/git#deploying-code
$ git push heroku yourbranch:main


[System] You are a helpful assistant.

[User]
How can I export GitHub issues to Excel?

How can I export all my issues from an Enterprise GitHub repository to an Excel file? I have tried searching many Stack Overflow answers but did not succeed. I tried this solution too (exporting Git issues to CSV and getting  "ImportError: No module named requests" errors. Is there any tool or any easy way to export all the issues to Excel?

[Assistant]
With the official GitHub CLI you can easily export all issues into a CSV format.
brew install gh

Log in:
gh auth login

Change directory to a repository and run this command:
gh issue list --limit 1000 --state all | tr '\t' ',' > issues.csv

In the European .csv files the separator is a semicolon ';', not a comma. Modify the separator as you want.


[System] You are a helpful assistant.

[User]
Defining parallel sequences of jobs in GitLab CI

In my gitlab-ci.yml file, I have defined 3 stages, and the 2nd and 3rd stages have 3 jobs each, resulting in the following structure:

The 1st and 2nd stage works as I intended, however, for the 3rd stage what I'd actually like to have is something like this (the image is a mockup of course), i.e. "parallel sequences" of jobs if you will:

That is, I want "deploy-b" to start if "build-b" is done, and not waiting for the other build tasks to complete.
Is that possible with GitLab pipelines? (Apart from the obvious solution of defining just 2 stages, the second being "Build-and-Deploy", where I just "merge" the script steps of the current build-* and deploy-* jobs.)

[Assistant] This feature was added in the new GitLab release (v12.2)


[System] You are a helpful assistant.

[User]
Cannot determine the organization name for this 'dev.azure.com' remote URL
So I just updated to a new Visual Studio version and I am no longer able to push/pull from/to my Azure Repo (cloning works fine). The exact error I get is

Cannot determine the organization name for this 'dev.azure.com' remote
url. ensure the credential.usehttppath configuration value is set,
or set the organization name as the user in the remote url
'{org}@dev.azure.com'.

and only the pull command shows me this error, all the others are failing with git fatal error. I messed with my Credentials Manager cos I suspected it might be the one causing the problem but no luck.

[Assistant]
What fixed the issue for me is going to Tools > Options > Source Control > Git Global Settings, there I changed all 4 dropdowns which were still selected as "Unset":

Prune remote branches during fetch - False
Rebase local branch when pulling - False
Cryptographic network provider - OpenSSL
Credential helper - GCM Core

Source: https://learn.microsoft.com/en-us/visualstudio/ide/git-with-visual-studio?view=vs-2019#personalize-your-git-settings
Note: These are the settings my organization requires. You might have to tweak them around according to your exact issue.


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  revision

[Assistant] Synonym for commit (the noun).


[System] You are a helpful assistant.

[User]
How to change git repository using android studio

I'm using git with android studio and I already sync other repository.
But I hope to change a git repository like github.
I think I need to disconnect already connected to the repository but I don't found this option.
To do that, How can I do?

[Assistant]
We can change the repository url. Just follow the steps.
In Android Studio Arctic Fox | 2020.3.1

Right click on project folder
From menu Choose “Git”
Then chosse "Manage Remotes..."
Now, select the existing "origin" and click on edit
Enter your new URL and click OK

For Android Studio Older versions

Right click on project folder
From menu Choose “Git”
Choose “Repository”
Choose “Remotes…”

Now you got the “Git Remotes” popup

You can edit the existing url or remove the old url and then add new url.
Click “OK”. that’s it. Now you are connected with new repo. But branches are not connected. Just follow few steps to complete.
Try to pull the changes from repo “Git > Repository > Pull…”
Now you got the “Pull Changes” popup. Click “Refresh” button.

After successfully reconnected with repo then you can see the branches of new repo under “Branches to merge” box.

Done. Now you are connected with new repo & branches.

Happy Coding :)


[System] You are a helpful assistant.

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

[Assistant]
Any line that is added in one location and was removed
in another location will be colored with color.diff.newMoved .
Similarly color.diff.oldMoved will be used for removed lines
that are added somewhere else in the diff. This mode picks up any
moved line, but it is not very useful in a review to determine
if a block of code was moved without permutation.


[System] You are a helpful assistant.

[User]
Repair corrupted Git repository
My Git repository got corrupted after a couple of hard reboots due to power supply issues and now I'm unable to fix it (I was in the middle of staging some files at the last power failure):
$ git status
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git fsck
fatal: failed to read object 24377c609184c192f3f3c1733bac7115c1080758: Invalid argument
$ git branch -a
(...works, lists branches...)
$ git checkout someotherbranch
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git log
fatal: failed to read object 3d18855708b0f127d40c13c679559d7679228b69: Invalid argument
$ git log someotherbranch
(...works, shows commits...)

So, as you can see, my current branch is pretty screwed up, and I don't seem to be able to fix it. What can I try to repair this?

[Assistant] My solution for a similar situation was to replace a hash of the damaged object in .git/refs/heads/my-working-branch with a hash of previous commit (which can be found in .git/logs/HEAD).