[System] You are a helpful assistant.

[User]
Unable to modify git bash Windows shortcut
Under Windows 7 I'd like to change the settings for the Git Bash Here shell extension command window, e.g. width, height and font. But when I do this, I get an error "Unable to modify the shortcut".
I can modify the shortcut for Git Bash in the Start menu by using "Run as administrator..." This works, but only for Bash windows opened from the Start menu. It doesn't work for the "Git Bash Here" shell extension and there's no "Run as administrator..." option on right-click context menu.
How do you do it?

[Assistant]
2020 Update
KVN posted an update for Windows 10

This one seems to be simplier and works well for me on the latest Git.

Right-click C:\Program Files\Git\git-bash.exe (Git for Windows)
Click Properties
Click the Compatibility tab in the Properties dialog
Check the "Run This Program As An Administrator" check box
Click OK button

Older
If you run git bash as administrator by right clicking on its icon and selecting "Run As Administrator" you will be able to change your settings and have them persist.
You can verify this by closing the admin session then reopening as a normal user.
I did this to set the defaults then just used git as a normal user from then on.
Edit: My answer is outdated if you're using the most recent msysgit version and sebastien.b posted the updated solution with - https://stackoverflow.com/a/7216120/104783
It states

The fix is to edit the Git Bash.vbs script and have it execute the link again, instead of sh.exe. Look for this line:

Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")

and replace it with this line:

Dim bash : bash = fso.BuildPath(gitdir, "Git Bash.lnk")

andrej351 also has a good reminder

Also, don't forget to select "Defaults" instead of "Properties" from the drop down menu in order to have the settings persisted


[System] You are a helpful assistant.

[User] git-rebase - Reapply commits on top of another base tip  --show-current-patch

[Assistant]
Show the current patch in an interactive rebase or when rebase
is stopped because of conflicts. This is the equivalent of git show REBASE_HEAD .


[System] You are a helpful assistant.

[User]
Is "refs/heads/master" same as "refs/remotes/origin/master" in Git?
The question is simple: is refs/heads/master the same thing as refs/remotes/origin/master? If it is not in some cases, how can I know when it is not and what it is then?

[Assistant]
They are two different symbolic names that can point to different things.  refs/heads/master is a branch in your working copy named master.  Frequently that is a tracking branch of refs/remotes/origin/master because origin is the default name for the remote created by git clone and its primary branch is usually also named master.
You can see the difference between them with git rev-list refs/heads/master..refs/remotes/origin/master which will be empty if they are the same and will otherwise list the commits between them.


[System] You are a helpful assistant.

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

[Assistant] Do not ignore whitespace when performing move detection.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  gui.encoding

[Assistant]
Specifies the default character encoding to use for displaying of
file contents in git-gui and gitk .
It can be overridden by setting the encoding attribute
for relevant files (see gitattributes ).
If this option is not set, the tools default to the
locale encoding.


[System] You are a helpful assistant.

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

[Assistant] a valid tag name (i.e. a refs/tags/<tag> reference).


[System] You are a helpful assistant.

[User] git - the stupid content tracker  --no-lazy-fetch

[Assistant]
Do not fetch missing objects from the promisor remote on
demand.  Useful together with git cat-file -e <object> to
see if the object is locally available.
This is equivalent to setting the GIT_NO_LAZY_FETCH environment variable to 1 .


[System] You are a helpful assistant.

[User] git-switch - Switch branches  --orphan <new-branch>

[Assistant]
Create a new unborn branch, named <new-branch> . All
tracked files are removed.


[System] You are a helpful assistant.

[User]
how do I correctly paste multi-line xml snippet to github wiki when using markdown

I am trying to create a github wiki for my project. But I am unable to format a snippet from a Spring beans xml file, into this wiki. What is the proper way to do it? I tried using pre tag, code tag, the multiline code tag etc. But either it is not getting displayed at all or It displays everything in the same line.

[Assistant]
not 100% sure if this is the same thing or not, but I just setup some xml snippets in my readme.md and used the
<myxml>
   <someElement />
</myxml>

notation.


[System] You are a helpful assistant.

[User]
Gitlab: Sorry, we cannot cherry-pick this merge request automatically

I got following error in the Gitlab:
Sorry, we cannot cherry-pick this merge request automatically. This merge request may already have been cherry picked, or a more recent commit may have updated some of its content.

I have branch X from which I have to cherry pick commits to the branch Y. Maybe I have already done cherry pick, which is after this failed cherry pick. I have about 10 cherry picks to do.
What I should to do?
I was thinking if I create new branch Z (before Y) and try add cherry picks in the right order. Maybe that would be solution? What you think?

[Assistant]
I did the cherry picks so that I picked up the merge request commits with commands like this:
git cherry-pick -m 1 <merge request commit hash 1>
git cherry-pick -m 1 <merge request commit hash 2>
...
git cherry-pick -m 1 <merge request commit hash N>

The -m 1 parameter is a little bit cryptical in the documentation, but I have done a lot of cherry picks and this is working.


[System] You are a helpful assistant.

[User]
How to convert files in GitHub repository to a Gist

What I would like to do is the inverse of this question.  I have a folder within a GitHub repo that contains a d3 visualization that I would like to continue making changes to.  It would be nice to have a "gist" version of this repo to display the visualization on bl.ocks.org that I could push changes to when from the primary repo after I am happy with them.
Another similar question is here, but the answers describe the step gist -> bl.ocks.org.  I am unsure of the step githup repo -> gist.  What is the best way to accomplish this?

[Assistant]
First of all, note that Gist doesn't support directories. To import a repository into a gist follow the next steps:

Create a new gist and clone it locally (replace the dummy id with your Gist id):
git clone [email protected]:792bxxxxxxxxxxxxxxx9.git

cd to that gist directory
Pull and merge from your GitHub repository:
git pull [email protected]:<user>/<repo>.git

Push your changes
git push

Again, note that if you have directories, you have to delete and commit them:
rm -rf some-directory
git commit -m 'Removed some-directory' .

Using the steps above, the project history will be kept. If you don't care about history, you can always push files in your Gist. Let's say you have a repository containing multiple folders and you want for each folder to create a Gist. You will repeat the next steps (or a script could do that):
git clone [email protected]:<gist-id>.git
cd <gist-id>
cp ../path/to/your/github/repository/and/some/folder/* .
git add .
git commit -m 'Added the Gist files' .
git push

Gist is different than how GitHub works:

Gist is a simple way to share snippets and pastes with others. All gists are Git repositories, so they are automatically versioned, forkable and usable from Git.

However, if you try to push directories in Gists you will get errors from remote:
$ git push
Counting objects: 32, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (32/32), 7.35 KiB | 0 bytes/s, done.
Total 32 (delta 10), reused 0 (delta 0)
remote: Gist does not support directories.
remote: These are the directories that are causing problems:
remote: foo
To [email protected]:792.....0b79.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:79.......9.git'


[System] You are a helpful assistant.

[User]
Create pull request with github action

I'm trying to make it work this action, but I'm confused also whats it's missing in between, before triggering the peter-evans PR.
The scenario is pretty simple, I like on push, on any feature/* branch, to create automatically PR, but instead I'm getting weird scenario, where develop changes are applied on top of the feature/* branch. Can someone give me hints on this?
name: Pull Request Action
on:
  push:
    branches:
      - feature/*

jobs:
  create-pull-request:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: develop

      - name: Create Pull Request
        uses: peter-evans/[email protected]
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Simple demo
          title: '[Example] Simple demo'
          body: >
            This PR is auto-generated by
            [create-pull-request](https://github.com/peter-evans/create-pull-request).
          labels: feature, automated pr
          branch: feature/workflow-demo

[Assistant]
I know this question is a year old now and asking about the create-pull-request action, but for those that would rather not use third-party actions,  Github actions now support Github command line natively, if you use  Github hosted runners. See: Using Github CLI in Workflows
This makes it super easy to create a pull request using the gh pr create command
Something like this:
  steps:
    - name: create pull request
      run: gh pr create -B base_branch -H branch_to_merge --title 'Merge branch_to_merge into base_branch' --body 'Created by Github action'
      env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


[System] You are a helpful assistant.

[User]
How to share a bit bucket repository with another user?
I am using Bit bucket and I have a friend that I would like to share my repository with. I am using the free individual account. There seems to be an option of creating a team in bit bucket but it says it will convert my account from individual to team account. I do not want that. How can I give another user access to this repository?

[Assistant]
There is an option of share link, if you click on that, a popup will be appeared on that you can give your friends username or his email to share the repository. This popup says something like
"Existing users are granted access to this repository immediately. New users will be sent an invitation."
UPDATE: Looks like the interface is slightly changed. You can share a repo via Settings / Access management.


[System] You are a helpful assistant.

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

[Assistant]
Show whole function as context lines for each change.
The function names are determined in the same way as git diff works out patch hunk headers (see Defining a
custom hunk-header in gitattributes ).


[System] You are a helpful assistant.

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

[Assistant] author date, relative


[System] You are a helpful assistant.

[User] git-init - Create an empty Git repository or reinitialize an existing one  --object-format= <format>

[Assistant]
Specify the given object <format> (hash algorithm) for the repository.  The valid
values are sha1 and (if enabled) sha256 . sha1 is the default. Note: At present, there is no interoperability between SHA-256
repositories and SHA-1 repositories.


[System] You are a helpful assistant.

[User] git-fast-import - Backend for fast Git data importers  fastimport.unpackLimit

[Assistant] See git-config


[System] You are a helpful assistant.

[User]
How to shallow clone a specific commit with depth 1?
Is it possible to shallow clone a specific commit in a repository, i.e. with depth 1? Something like
git clone http://myrepo.git 728a4d --depth 1

to get the repository state as it is at the commit with SHA 728a4d...?
The motivation is to avoid having to clone the whole repository, then check out that specific commit, when we're only interested in the state of the repository at that specific commit.

[Assistant]
Starting with Git 2.5.0 (which needs to be available at both the client and server side) you can set uploadpack.allowReachableSHA1InWant=true on the server side to enable fetching of specific SHA1s (must be the full SHA1, not an abbreviation):
git init
git remote add origin <url>
git fetch --depth 1 origin <sha1>
git checkout FETCH_HEAD

Note that I did not find a syntax to do this with git clone directly.


[System] You are a helpful assistant.

[User] git-rev-list - Lists commit objects in reverse chronological order  %al

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


[System] You are a helpful assistant.

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

[Assistant]
Show <eolinfo> and <eolattr> of files.
<eolinfo> is the file content identification used by Git when
the "text" attribute is "auto" (or not set and core.autocrlf is not false).
<eolinfo> is either "-text", "none", "lf", "crlf", "mixed" or "". "" means the file is not a regular file, it is not in the index or
not accessible in the working tree. <eolattr> is the attribute that is used when checking out or committing,
it is either "", "-text", "text", "text=auto", "text eol=lf", "text eol=crlf".
Since Git 2.10 "text=auto eol=lf" and "text=auto eol=crlf" are supported. Both the <eolinfo> in the index ("i/<eolinfo>")
and in the working tree ("w/<eolinfo>") are shown for regular files,
followed by the  ("attr/<eolattr>").


[System] You are a helpful assistant.

[User]
Can you delete multiple branches in one command with Git?
I'd like to clean up my local repository, which has a ton of old branches: for example 3.2, 3.2.1, 3.2.2, etc.
I was hoping for a sneaky way to remove a lot of them at once. Since they mostly follow a dot release convention, I thought maybe there was a shortcut to say:
git branch -D 3.2.*

and kill all 3.2.x branches.
I tried that command and it, of course, didn't work.

[Assistant]
Not with that syntax. But you can do it like this:
git branch -D 3.2 3.2.1 3.2.2

Basically, git branch will delete multiple branch for you with a single invocation. Unfortunately it doesn't do branch name completion. Although, in bash, you can do:
git branch -D `git branch | grep -E '^3\.2\..*'`


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  --no-indent-heuristic

[Assistant] Disable the indent heuristic.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  %(trailers[:<options>])

[Assistant]
display the trailers of the body as interpreted by git-interpret-trailers . The trailers string may be followed by
a colon and zero or more comma-separated options. If any option is provided
multiple times, the last occurrence wins. key=<key> : only show trailers with specified <key>. Matching is done
case-insensitively and trailing colon is optional. If option is
given multiple times trailer lines matching any of the keys are
shown. This option automatically enables the only option so that
non-trailer lines in the trailer block are hidden. If that is not
desired it can be disabled with only=false .  E.g., %(trailers:key=Reviewed-by) shows trailer lines with key Reviewed-by . only[=<bool>] : select whether non-trailer lines from the trailer
block should be included. separator=<sep> : specify the separator inserted between trailer
lines. Defaults to a line feed character. The string <sep> may contain
the literal formatting codes described above. To use comma as
separator one must use %x2C as it would otherwise be parsed as
next option. E.g., %(trailers:key=Ticket,separator=%x2C ) shows all trailer lines whose key is "Ticket" separated by a comma
and a space. unfold[=<bool>] : make it behave as if interpret-trailer’s --unfold option was given. E.g., %(trailers:only,unfold=true) unfolds and shows all trailer lines. keyonly[=<bool>] : only show the key part of the trailer. valueonly[=<bool>] : only show the value part of the trailer. key_value_separator=<sep> : specify the separator inserted between
the key and value of each trailer. Defaults to ": ". Otherwise it
shares the same semantics as separator=<sep> above.


[System] You are a helpful assistant.

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

[Assistant] Graphical alternative to git-commit


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  imap.tunnel

[Assistant]
Command used to set up a tunnel to the IMAP server through which
commands will be piped instead of using a direct network connection
to the server. Required when imap.host is not set.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  log.mailmap

[Assistant]
If true, makes git-log , git-show , and git-whatchanged assume --use-mailmap , otherwise
assume --no-use-mailmap . True by default.


[System] You are a helpful assistant.

[User] git-pull - Fetch from and integrate with another repository or a local branch  --[no-]recurse-submodules[=(yes|on-demand|no)]

[Assistant]
This option controls if new commits of populated submodules should
be fetched, and if the working trees of active submodules should be
updated, too (see git-fetch , git-config and gitmodules ). If the checkout is done via rebase, local submodule commits are rebased as well. If the update is done via merge, the submodule conflicts are resolved and checked out.


[System] You are a helpful assistant.

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

[Assistant]
Added content is represented by lines beginning with "+". You can
prevent staging any addition lines by deleting them.


[System] You are a helpful assistant.

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

[Assistant]
The object that the new tag will refer to, usually a commit.
Defaults to HEAD.


[System] You are a helpful assistant.

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

[Assistant]
Set to false to enable --no-show-forced-updates in git-fetch and git-pull commands.
Defaults to true.


[System] You are a helpful assistant.

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

[Assistant]
Output only the last line of the --stat format containing total
number of modified files, as well as number of added and deleted
lines.


[System] You are a helpful assistant.

[User]
How do I provide a username and password when running "git clone [email protected]"?
I know how to include a username and password in an HTTPS Git URL like this:
git clone https://username:password@host

But I'd like to know how to provide a username and password to an SSH remote like this:
git clone [email protected]

I've tried like this:
git clone username:password@[email protected]
git clone git@username:[email protected]
git clone [email protected]@username:password

But they haven't worked.

[Assistant]
Based on Michael Scharf's comment:
You can leave out the password, so that it won't be logged in your Bash history file:
git clone https://[email protected]/username/repository.git

It will prompt you for your password.
Alternatively, you may use:
git clone https://username:[email protected]/username/repository.git

This way worked for me from a GitHub repository.


[System] You are a helpful assistant.

[User]
Firebase: Should I add GoogleService-Info.plist to .gitignore?

I'm using Firebase for an iOS project that I want to open source.
Should I add GoogleService-Info.plist to .gitignore before I upload I share the project on Github?
I know it contains my API key, client id, etc., which might not be safe to expose?

[Assistant]
While it's not the end of the world if you commit GoogleService-Info.plist (similarly, on Android, google-services.json), you're better off leaving it out for one big reason: You're making it clear that others who build your code that they should be setting up their own Firebase project to host its configuration and data (because your project simply won't build with that file missing).  Furthermore, if your project has world-writable resources in it, you can expect that people who get a hold of your app and config so easily will inadvertently start writing data into it, which is probably not what you want.
Open source projects that require a Firebase setup should ideally have it stated in the readme that anyone who wants to work with this app needs to go through the process of setting up Firebase.
The data in these config files is not exactly private - they can be extracted fairly easily from an IPA or Android APK.  It's just probably not in your best interest to share them as part of your app's code.


[System] You are a helpful assistant.

[User]
Nested Git repositories?
Can I nest Git repositories? I have:
 /project_root/
 /project_root/my_project
 /project_root/third_party_git_repository_used_by_my_project

Does it make sense to git init/add the /project_root to ease management of everything locally or do I have to manage my_project and the 3rd party one separately?

[Assistant] You may be looking for the Git feature called submodules. This feature helps you manage dependent repositories that are nested inside your main repository.


[System] You are a helpful assistant.

[User]
Github: Import upstream branch into fork

I have a fork (origin) from a project (upstream) on github. Now the upstream project has added a new branch, I want to import into my fork. How do I do that?
I tried checking out the remote and creating a branch on top of that, but that configures the branch the way that git push is trying to push to the upstream:
git checkout upstream/branch
git checkout -b branch

edit
Maybe that wasn't clear, but I want to add the branch to my local repository, so I can push it to origin (my fork) via git push. Because upstream repositories are usually read-only and you fork it to contribute.
So I basically want to checkout a non-existent branch on origin whose contents will be pulled in from upstream.

[Assistant]
Make sure you've pulled the new upstream branch into your local repo:

First, ensure your working tree is clean (commit/stash/revert any changes)
Then, git fetch upstream to retrieve the new upstream branch

Create and switch to a local version of the new upstream branch (newbranch):

git checkout -b newbranch upstream/newbranch

When you're ready to push the new branch to origin:

git push -u origin newbranch

The -u switch sets up tracking to the specified remote (in this example, origin)


[System] You are a helpful assistant.

[User] git-fetch - Download objects and refs from another repository  --refmap=<refspec>

[Assistant]
When fetching refs listed on the command line, use the
specified refspec (can be given more than once) to map the
refs to remote-tracking branches, instead of the values of remote.*.fetch configuration variables for the remote
repository.  Providing an empty <refspec> to the --refmap option causes Git to ignore the configured
refspecs and rely entirely on the refspecs supplied as
command-line arguments. See section on "Configured Remote-tracking
Branches" for details.


[System] You are a helpful assistant.

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

[Assistant]
Boolean value indicating if the submodule is of interest to git
commands.  This config option takes precedence over the
submodule.active config option. See gitsubmodules for
details.


[System] You are a helpful assistant.

[User] git-pull - Fetch from and integrate with another repository or a local branch  --shallow-since=<date>

[Assistant]
Deepen or shorten the history of a shallow repository to
include all reachable commits after <date>.


[System] You are a helpful assistant.

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

[Assistant]
Turn off rename detection, even when the configuration
file gives the default to do so.


[System] You are a helpful assistant.

[User]
How to extract a git subdirectory and make a submodule out of it?
I started a project some months ago and stored everything within a main directory.
In my main directory "Project" there are several subdirectories containing different things:
Project/paper contains a document written in LaTeX
Project/sourcecode/RailsApp contains my rails app.
"Project" is GITified and there have been a lot of commits in both "paper" and "RailsApp" directory. Now, as I'd like to use cruisecontrol.rb for my "RailsApp" I wonder if there is a way to make a submodule out of "RailsApp" without losing the history.

[Assistant]
Nowadays there's a much easier way to do it than manually using git filter-branch: git subtree
Installation
NOTE git-subtree is now part of git (if you install contrib) as of 1.7.11, so you might already have it installed. You may check by executing git subtree.

To install git-subtree from source (for older versions of git):
git clone https://github.com/apenwarr/git-subtree.git

cd git-subtree
sudo rsync -a ./git-subtree.sh /usr/local/bin/git-subtree

Or if you want the man pages and all
make doc
make install

Usage
Split a larger into smaller chunks:
# Go into the project root
cd ~/my-project

# Create a branch which only contains commits for the children of 'foo'
git subtree split --prefix=foo --branch=foo-only

# Remove 'foo' from the project
git rm -rf ./foo

# Create a git repo for 'foo' (assuming we already created it on github)
mkdir foo
pushd foo
git init
git remote add origin [email protected]:my-user/new-project.git
git pull ../ foo-only
git push origin -u master
popd

# Add 'foo' as a git submodule to `my-project`
git submodule add [email protected]:my-user/new-project.git foo

For detailed documentation (man page), please read git-subtree.txt.


[System] You are a helpful assistant.

[User]
How to emulate git log --decorate's different colors per branch-type
In making my favorite git log view I've created this alias:
graph = log --pretty=format:'%Cgreen%ad%Creset %C(yellow)%h%Creset%C(yellow)%d%Creset %s %C(cyan)[%an]%Creset %Cgreen(%ar)%Creset' --date=short --graph
This creates an output like:

What I'm missing here is the different coloring of branch types like in log --oneline --decorate --graph.

The --decorate (which uses =short by default) gives the different recognized branches a different color. The branch types (HEAD, origin/master, origin/HEAD, master) are colored cyan, red, red, green. Mine however are uncolored; colored only with the yellow of the whole branches part.
Is there a way to give different colors to the different kind of branches with an own alias?

[Assistant]
Per https://stackoverflow.com/a/16844346/55948

As of git 1.8.3 (May 24, 2013), you can use %C(auto) to decorate
  %d in the format string of git log.
From the release
  notes:
 * "git log --format" specifier learned %C(auto) token that tells Git
   to use color when interpolating %d (decoration), %h (short commit
   object name), etc. for terminal output.)


[System] You are a helpful assistant.

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

[Assistant] Name for the new branch.


[System] You are a helpful assistant.

[User]
What does Bump Version stand for?
I saw this comment in git many times.
What does it mean actually?

[Assistant] It means to increment the version number to a new, unique value.


[System] You are a helpful assistant.

[User] git-rev-list - Lists commit objects in reverse chronological order  %e

[Assistant] encoding


[System] You are a helpful assistant.

[User]
Adding to someone else’s pull request on a GitHub project that I do not own

Is it possible for me to add commits to someone else’s pull request on a repository where I am not the owner?
e.g.
User A owns Project X.
User B forks Project X, creates a feature branch, makes some changes, and submits a pull request.
User C likes the pull request, but would like to make some modifications to it. (FWIW User C already has a fork of Project X, so is unable to easily fork User B’s fork).
Can User C add commits to User B’s PR?

[Assistant]
You can check out the branch and re-submit a modified PR (giving credit to the original, preferably).
You can also issue a PR to the PR author:
git remote add userb https://github.com/userb/name.git
git fetch userb
git checkout featurebranch
[change and commit]
git push userc featurebranch

When you create a PR, GitHub lets you choose the base branch - so you can choose the fork and - if you want to - request changes to the PR.


[System] You are a helpful assistant.

[User] git-submodule - Initialize, update or inspect submodules  --remote

[Assistant]
This option is only valid for the update command.  Instead of using
the superproject’s recorded SHA-1 to update the submodule, use the
status of the submodule’s remote-tracking branch.  The remote used
is branch’s remote ( branch.<name>.remote ), defaulting to origin .
The remote branch used defaults to the remote HEAD , but the branch
name may be overridden by setting the submodule.<name>.branch option in either .gitmodules or .git/config (with .git/config taking precedence). This works for any of the supported update procedures ( --checkout , --rebase , etc.).  The only change is the source of the target SHA-1.
For example, submodule update --remote --merge will merge upstream
submodule changes into the submodules, while submodule update
--merge will merge superproject gitlink changes into the submodules. In order to ensure a current tracking branch state, update --remote fetches the submodule’s remote repository before calculating the
SHA-1.  If you don’t want to fetch, you should use submodule update
--remote --no-fetch . Use this option to integrate changes from the upstream subproject with
your submodule’s current HEAD.  Alternatively, you can run git pull from the submodule, which is equivalent except for the remote branch
name: update --remote uses the default upstream repository and submodule.<name>.branch , while git pull uses the submodule’s branch.<name>.merge .  Prefer submodule.<name>.branch if you want
to distribute the default upstream branch with the superproject and branch.<name>.merge if you want a more native feel while working in
the submodule itself.


[System] You are a helpful assistant.

[User]
How do I get my 'Detached HEAD' commits back into master [duplicate]
This question already has answers here:

How can I reconcile detached HEAD with master/origin?

                                (29 answers)

Closed 8 years ago.

Looks like a few days ago I created a branch called detached HEAD and have been committing to it.  My normal process is to commit to master and then push that to origin.  But I can't push detached HEAD.
My next stop screwed me. I selected git checkout master - and my detached HEAD branch disappeared. Going back to my project all of my changes in the past few days have been wiped.
Is there anyway I can get those changes back?

[Assistant]
If checkout master was the last thing you did, then the reflog entry HEAD@{1} will contain your commits (otherwise use git reflog or git log -p to find them). Use git merge HEAD@{1} to fast forward them into master.
As noted in the comments, Git Ready has a great article on this.
git reflog and git reflog --all will give you the commit hashes of the mis-placed commits.

Source: http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  --line-prefix=<prefix>

[Assistant] Prepend an additional prefix to every line of output.


[System] You are a helpful assistant.

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

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


[System] You are a helpful assistant.

[User] git-rebase - Reapply commits on top of another base tip  --skip

[Assistant] Restart the rebasing process by skipping the current patch.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --date-order

[Assistant]
Show no parents before all of its children are shown, but
otherwise show commits in the commit timestamp order.


[System] You are a helpful assistant.

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

[Assistant]
After performing a merge, the original file with conflict markers
can be saved as a file with a .orig extension.  If this variable
is set to false then this file is not preserved.  Defaults to true (i.e. keep the backup files).


[System] You are a helpful assistant.

[User] git-init - Create an empty Git repository or reinitialize an existing one  --bare

[Assistant]
Create a bare repository. If GIT_DIR environment is not set, it is set to the
current working directory.


[System] You are a helpful assistant.

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

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


[System] You are a helpful assistant.

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

[Assistant] Rename the given section to a new name.


[System] You are a helpful assistant.

[User] git-grep - Print lines matching a pattern  -e

[Assistant]
The next parameter is the pattern. This option has to be
used for patterns starting with - and should be used in
scripts passing user input to grep.  Multiple patterns are
combined by or .


[System] You are a helpful assistant.

[User]
What are the pros and cons of git-flow vs github-flow? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 4 years ago.

                        Improve this question

We have recently started to use GitLab.
Currently using a "centralized" workflow.
We are considering moving to the github-flow but I want to make sure.
What are the pros and cons of git-flow vs github-flow?

[Assistant]
As discussed in GitMinutes episode 17, by Nicholas Zakas in his article on  "GitHub workflows inside of a company":

Git-flow is a process for managing changes in Git that was created by Vincent Driessen and accompanied by some Git extensions for managing that flow.
  The general idea behind git-flow is to have several separate branches that always exist, each for a different purpose: master, develop, feature, release, and hotfix.
  The process of feature or bug development flows from one branch into another before it’s finally released.
Some of the respondents indicated that they use git-flow in general.
  Some started out with git-flow and moved away from it.
The primary reason for moving away is that the git-flow process is hard to deal with in a continuous (or near-continuous) deployment model.
The general feeling is that git-flow works well for products in a more traditional release model, where releases are done once every few weeks, but that this process breaks down considerably when you’re releasing once a day or more.

In short:
Start with a model as simple as possible (like GitHub flow tends to be), and move towards a more complex model if you need to.

You can see an interesting illustration of a simple workflow, based on GitHub-Flow at:
"A simple git branching model", with the main elements being:

master must always be deployable.
all changes made through feature branches (pull-request + merge)
rebase to avoid/resolve conflicts; merge in to master

For an actual more complete and robust workflow, see gitworkflow (one word).


[System] You are a helpful assistant.

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

[Assistant]
Read refspecs, one per line, from stdin in addition to those provided
as arguments. The "tag <name>" format is not supported.


[System] You are a helpful assistant.

[User]
Git: How to revert 2 files that are stubbornly stuck at "Changed but not committed"?
I have a repo that has two files that supposedly I changed locally.
So I'm stuck with this:
$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   dir1/foo.aspx
#       modified:   dir2/foo.aspx
#
no changes added to commit (use "git add" and/or "git commit -a")

Doing git diff says that the entire file contents have changed, even though from eyeballing it that seems untrue (there seem to be common line ranges that diff seems to be failing to see).
Interestingly I don't remember changing these files locally. This repo is used with one remote repo (private, at GitHub.com, FWIW).
No matter what I've tried, I can't discard these local changes. I have tried all of:
$ git checkout -- .
$ git checkout -f
$ git checkout -- dir1/checkout_receipt.aspx
$ git reset --hard HEAD
$ git stash save --keep-index && git stash drop
$ git checkout-index -a -f

In other words I've tried everything described in How do I discard unstaged changes in Git? plus more. But the 2 files remain stuck as "changed but not committed".
What the heck would cause two files to be stuck like this and seemingly "un-revert-table"??
P.S. In the list above showing commands I'd already tried, I mistakenly wrote git revert when I meant git checkout. I'm sorry and thank you to those of you who answered that I should try checkout. I edited the question to correct it. I definitely did already try checkout.

[Assistant]
I spent hours trying to solve a similar issue - a remote branch that I had checked out, which stubbornly showed four files as 'Changed but not updated', even when deleting all files and running git checkout -f again (or other variations from this post)!
These four files were necessary, but certainly hadn't been modified by me. My final solution - persuade Git that they had not been changed. The following works for all checked out files, showing 'modified' status - make sure you have already committed/stashed any that have really been modified!:
git ls-files -m | xargs -i git update-index --assume-unchanged "{}"

On Mac OSX, however xargs operates a little bit different (thx Daniel for the comment):
git ls-files -m | xargs -I {} git update-index --assume-unchanged {}

I've added this as a placeholder for myself for next time.


[System] You are a helpful assistant.

[User]
What is the preferred way to manage schema.rb in git?
I don't want to add schema.rb to .gitignore, because I want to be able to load a new database schema from that file.  However, keeping it checked in is causing all sorts of spurious conflicts that are easily resolved by a fresh db:migrate:reset.
Basically I want a way to:

Keep schema.rb in the repository for deploy-time database setup
Keep schema.rb in '.gitignore' for general development

There would be one or two people responsible for updating schema.rb and knowing that it was correct.
Is there a way I can have my cake and eat it, too?

[Assistant] I'm afraid the magic solution you're looking for does not exist.  This file is normally managed in version control, then for any conflicts on the version line just choose the later of the two dates.  As long as you're also running all of the associated migrations nothing should get out of sync this way.  If two developers have caused modifications to a similar area of schema.rb and you get conflicts in addition to the version then you are faced with a normal merge conflict resolution, but in my opinion these are normally easy to understand and resolve.  I hope this helps some!


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  gitweb.category  gitweb.description  gitweb.owner  gitweb.url

[Assistant] See gitweb for description.


[System] You are a helpful assistant.

[User]
Jenkins fails to build when I use a parameterised branch: fatal: Couldn't find remote ref refs/heads/${BUILD_BRANCH}

As soon as I attempted to upgrade my Jenkins job to use a parameter for the branch rather than a hard coded value it no longer works.

Have tried many other names than BUILD_BRANCH

Here I've tried ${env.BUILD_BRANCH}, refs/heads${BUILD_BRANCH} and absolutely none of them work

When I did this initially I did check lightweight checkout, I removed it after reading many online answers from those having the same problem. Still nothing!. I just added the 'wipe' command to see if that would help but it didn't
error:
 > git rev-list --no-walk 97428a402f3304a21ccc8df435a40468ebf406c1 # timeout=10
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] readTrusted
[Pipeline] End of Pipeline
hudson.plugins.git.GitException: Command "git fetch --tags --progress --prune -- origin +refs/heads/${BUILD_BRANCH}:refs/remotes/origin/${BUILD_BRANCH}" returned status code 128:
stdout:
stderr: fatal: Couldn't find remote ref refs/heads/${BUILD_BRANCH}
fatal: The remote end hung up unexpectedly

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2429)

Thank you for reading even if you couldn't help

[Assistant] Do you have lightweight checkout selected in the Pipeline SCM section? Unchecking lightweight checkout fixed this issue for me.


[System] You are a helpful assistant.

[User] git-rebase - Reapply commits on top of another base tip  -X <strategy-option>  --strategy-option=<strategy-option>

[Assistant]
Pass the <strategy-option> through to the merge strategy.
This implies --merge and, if no strategy has been
specified, -s ort .  Note the reversal of ours and theirs as noted above for the -m option. See also INCOMPATIBLE OPTIONS below.


[System] You are a helpful assistant.

[User] git-merge - Join two or more development histories together  merge.autoStash

[Assistant]
When set to true, automatically create a temporary stash entry
before the operation begins, and apply it after the operation
ends.  This means that you can run merge on a dirty worktree.
However, use with care: the final stash application after a
successful merge might result in non-trivial conflicts.
This option can be overridden by the --no-autostash and --autostash options of git-merge .
Defaults to false.


[System] You are a helpful assistant.

[User]
Git pretty format colors
I'm trying to set up pretty format colors for Git.  From what I can tell version 1.6.0 only recognizes red, green and blue.
$ git log --pretty=format:"%Credred%Creset %Cgreengreen%Creset %Cyellowyellow%Creset %Cblueblue%Creset %Cmagentamagenta%Creset %Ccyancyan%Creset %Cwhitewhite%Creset"
red green %Cyellowyellow%Creset blue %Cmagentamagenta %Ccyancyan %Cwhitewhite

In addition none of the colors work with the parenthesized color format.
Is there a way to list the available pretty format colors for Git?
Unfortunately this is on a legacy SCO OpenServer 5.0.7 machine and the last version of Git released by SCO Skunkworks was 1.6.0.3.

[Assistant]
I do not have an old version of git to verify that the colors other than red, blue and green are supported.
Although, one thing I noticed even with the recent versions of git (like 1.7.10 I used) is that colors other than red, green and blue need to be within parentheses (). For red, green and blue, the parentheses are optional.
So give this a try:
git log --pretty=format:"%Credred%Creset %Cgreengreen%Creset %C(Yellow)yellow%Creset %Cblueblue%Creset %C(magenta)magenta%Creset %C(cyan)cyan%Creset %C(white)white%Creset"

The list of colors I'm aware of at least are:
normal
black
red
green
yellow
blue
magenta
cyan
white

It can be combined with one or more of these attributes:
bold
dim
ul
blink
reverse
italic
strike
bright  # (Git 2.26, Q1 2020, example: brightred)

If you're trying to change colors using .gitconfig you should be able to specify two colors - foreground and background and you can combine it with an attribute.


[System] You are a helpful assistant.

[User] git-rm - Remove files from the working tree and from the index  --ignore-unmatch

[Assistant] Exit with a zero status even if no files matched.


[System] You are a helpful assistant.

[User]
AzureDevOps - Link git commit or branch to work item via command line
I've worked on projects with a Jira integration where I simply had to include the ticket number in the commit or branch name and that work would automatically link with the ticket in Jira. Exe:

git commit -am '123 some commit'

And on the ticket you'd see a link to the commit.
How can I do that with Azure Dev Ops?
I know how to manually do it via Visual Studio or in the ticket itself, but I want to do it through the command line only.

[Assistant]
You can link a work item in Azure Boards to a commit in Azure Repos by specifying the work item ID after a pound sign.  Eg, to update work item #3, you need to mention #3 in the commit message.  (The pound sign - # is required, it won't parse bare numbers and try to link work items.)
For example:
git commit -m"Update bug #3"

Produces a bidirectional link between the commit and the work item.  You can see this in the commit details, in the work item tab:

And you can see this in the work item details, in the "Development" section:


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  --ws-error-highlight=<kind>

[Assistant]
Highlight whitespace errors in the context , old or new lines of the diff.  Multiple values are separated by comma, none resets previous values, default reset the list to new and all is a shorthand for old,new,context .  When
this option is not given, and the configuration variable diff.wsErrorHighlight is not set, only whitespace errors in new lines are highlighted. The whitespace errors are colored
with color.diff.whitespace .


[System] You are a helpful assistant.

[User]
My diff contains trailing whitespace - how to get rid of it?
I've tried editing a php file in TextWrangler with line endings set to Unix, in NetBeans, and in vim. When I save the diff to a patch and then try to apply it, it gives whitespace errors. When I type git diff I can see ^M at the ends of my lines, but if I manually remove these in vim, it says my patch file is corrupted, and then the patch doesn't apply at all.
I create a patch with the following command:
git diff > patchname.patch
And I apply it by checking out a clean version of the file to be patched and typing
git apply patchname.patch
How can I create this patch without whitespace errors? I've created patches before and never run into this issue.

[Assistant]
git apply --reject --whitespace=fix mychanges.path
Darian Lewin commented:

Useful to automatically fix whitespace errors. --whitespace=fix ensures whitespace errors are fixed before path is applied, and --reject ensures atomicity so no working directory files are modified if patch will not apply.
Source: git-scm.com/docs/git-apply


[System] You are a helpful assistant.

[User]
GitHub wiki directories

Does the wiki that installs with a GitHub repo support directories?  Our wiki is cluttered with pages, and we are looking for a way to organize them better.
We tried pulling the repo, creating local directories, and moving things around, but when committed back, the wiki didn't pick up the changes.

[Assistant]
I was having the exact same issue and tried variants of what you tried.  Nothing stuck.  Asked GitHub support about it and received a reply that essentially said "No, but we'll let the developers know that people are interested in this feature."
So the short answer is "No", and the long answer is "No, but maybe in the future."


[System] You are a helpful assistant.

[User] git-apply - Apply a patch to files and/or to the index  --recount

[Assistant]
Do not trust the line counts in the hunk headers, but infer them
by inspecting the patch (e.g. after editing the patch without
adjusting the hunk headers appropriately).


[System] You are a helpful assistant.

[User]
Using Git, how could I search for a string across all branches?
Using Git, how could I search within all files in all local branches for a given string?
GitHub specific: is it possible to perform the above search across all GitHub branches? (There are several remote branches on my remote GitHub repository that ideally I wouldn't have to bring down for this search...)

[Assistant]
You can do this on a Git repository:
git grep "string/regexp" $(git rev-list --all)

GitHub advanced search has code search capability:
The code search will look through all of the code publicly hosted on GitHub. You can also filter by:

the language: language:
the repository name (including the username):    repo:
the file path: path:


[System] You are a helpful assistant.

[User]
How to compare files from two different branches
I have a script that works fine in one branch and is broken in another. I want to look at the two versions side-by-side and see what's different. Is there a way to do this?
To be clear I'm not looking for a compare tool (I use Beyond Compare). I'm looking for a Git diff command that will allow me to compare the master version to my current branch version to see what has changed. I'm not in the middle of a merge or anything. I just want to say something like
git diff mybranch/myfile.cs master/myfile.cs

[Assistant]
git diff can show you the difference between two commits:
git diff mybranch master -- myfile.cs

Or, equivalently:
git diff mybranch..master -- myfile.cs

Note you must specify the relative path to the file. So if the file were in the src directory, you'd say src/myfile.cs instead of myfile.cs.
Using the latter syntax, if either side is HEAD it may be omitted (e.g., master.. compares master to HEAD).
You may also be interested in mybranch...master (from git diff documentation):

This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. git diff A...B is equivalent to git diff $(git-merge-base A B) B.

In other words, this will give a diff of changes in master since it diverged from mybranch (but without new changes since then in mybranch).

In all cases, the -- separator before the file name indicates the end of command line flags (mind the space between the separator and the filename). This is optional unless Git will get confused if the argument refers to a commit or a file, but including it is not a bad habit to get into. See Dietrich Epp's answer to Meaning of Git checkout double dashes for a few examples.

The same arguments can be passed to git difftool if you have one configured.


[System] You are a helpful assistant.

[User]
git revert back to certain commit [duplicate]
This question already has answers here:

How do I revert a Git repository to a previous commit?

                                (41 answers)

Closed 9 years ago.

how do i revert all my files on my local copy back to a certain commit?
commit 4a155e5b3b4548f5f8139b5210b9bb477fa549de
Author: John Doe <[email protected]>
Date:   Thu Jul 21 20:51:38 2011 -0500

This is the commit i'd like to revert back to. any help would be a lifesaver!

[Assistant] git reset --hard 4a155e5  Will move the HEAD back to where you want to be.  There may be other references ahead of that time that you would need to remove if you don't want anything to point to the history you just deleted.


[System] You are a helpful assistant.

[User]
Should you commit .gitignore into the Git repos?
Do you think it is a good practice to commit .gitignore into a Git repo?
Some people don't like it, but I think it is good as you can track the file's history. Isn't it?

[Assistant] Normally yes, .gitignore is useful for everyone who wants to work with the repository. On occasion you'll want to ignore more private things (maybe you often create LOG or something.  In those cases you probably don't want to force that on anyone else.


[System] You are a helpful assistant.

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

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


[System] You are a helpful assistant.

[User]
How do I edit an incorrect commit message in git ( that I've pushed )?
I want to modify a commit message deeper in history and I've pushed many new commits.
How do I change the commit message? Is it possible?

[Assistant]
The message from Linus Torvalds may answer your question:
Modify/edit old commit messages
Short answer: you can not (if pushed).

extract (Linus refers to BitKeeper as BK):

Side note, just out of historical interest: in BK you could.
And if you're used to it (like I was) it was really quite practical. I
  would apply a patch-bomb from Andrew, notice something was wrong, and just
  edit it before pushing it out.
I could have done the same with git. It would have been easy enough to
  make just the commit message not be part of the name, and still guarantee
  that the history was untouched, and allow the "fix up comments later"
  thing.
But I didn't.
Part of it is purely "internal consistency". Git is simply a cleaner
  system thanks to everything being SHA1-protected, and all objects being
  treated the same, regardless of object type. Yeah, there are four
  different kinds of objects, and they are all really different, and they
  can't be used in the same way, but at the same time, even if their
  encoding might be different on disk, conceptually they all work exactly
  the same.
But internal consistency isn't really an excuse for being inflexible, and
  clearly it would be very flexible if we could just fix up mistakes after
  they happen. So that's not a really strong argument.
The real reason git doesn't allow you to change the commit message ends
  up being very simple: that way, you can trust the messages. If you allowed
  people to change them afterwards, the messages are inherently not very
  trustworthy.

To be complete, you could rewrite your local commit history in order to reflect what you want, as suggested by sykora (with some rebase and reset --hard, gasp!)
However, once you publish your revised history again (with a git push origin +master:master, the + sign forcing the push to occur, even if it doesn't result in a "fast-forward" commit)... you might get into some trouble.
Extract from this other SO question:

I actually once pushed with --force to git.git repository and got scolded by Linus BIG TIME. It will create a lot of problems for other people. A simple answer is "don't do it".


[System] You are a helpful assistant.

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

[Assistant] If set, git diff uses this source prefix. Defaults to "a/".


[System] You are a helpful assistant.

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

[Assistant] Import from and submit to Perforce repositories


[System] You are a helpful assistant.

[User]
Version control of Mathematica notebooks
Mathematica notebooks are, of course, plaintext files -- it seems reasonable to expect that they should play nice with a version-control system (git in my case, although I doubt the specific system matters).  But the fact is that any .nb file is full of cache information, timestamps, and other assorted metadata.  Scads of it.
Which means that limited version control is possible -- commits and rollbacks work fine.  Merging, though, is a disaster.  Mathematica won't open a file with merge markers in it, and a text editor is no way to go through a .nb file.
Has anyone had any luck putting a notebook under version control?  How?

[Assistant]
It's recommended to disable the file outline cache, which is the metadata you're referring to when you look at the notebook with a text editor. As you discovered, it can cause merge conflicts if multiple parties are editing the same notebook.
This is easily disabled with the Option Inspector. In the Mathematica menu, go to Format → Option Inspector..., in the top-left set the scope dropdown to Selected Notebook and search for FileOutlineCache in the search field. Set the option to False and save your notebook, and you should be all set.
Note that this can make opening notebooks a little slower, but unless the notebook is rather large, you probably won't notice the difference.


[System] You are a helpful assistant.

[User]
How to use terminal commands with Github?
I have forked a private repository (an iPhone project) as follows:
cd nameofdirectory
git init
git clone forkedURL

Now I want to push the changes done by me to my forked repository so that the main admin can review my written code and merge it with the main repository.
How can I push the changes done by me to my forked repository using terminal on MacOS?

[Assistant]
You can't push into other people's repositories. This is because push permanently gets code into their repository, which is not cool.
What you should do, is to ask them to pull from your repository. This is done in GitHub by going to the other repository and sending a "pull request".
There is a very informative article on the GitHub's help itself: https://help.github.com/articles/using-pull-requests

To interact with your own repository, you have the following commands. I suggest you start reading on Git a bit more for these instructions (lots of materials online).
To add new files to the repository or add changed files to staged area:
$ git add <files>

To commit them:
$ git commit

To commit unstaged but changed files:
$ git commit -a

To push to a repository (say origin):
$ git push origin

To push only one of your branches (say master):
$ git push origin master

To fetch the contents of another repository (say origin):
$ git fetch origin

To fetch only one of the branches (say master):
$ git fetch origin master

To merge a branch with the current branch (say other_branch):
$ git merge other_branch

Note that origin/master is the name of the branch you fetched in the previous step from origin. Therefore, updating your master branch from origin is done by:
$ git fetch origin master
$ git merge origin/master

You can read about all of these commands in their manual pages (either on your linux or online), or follow the GitHub helps:

https://help.github.com/articles/create-a-repo for commit and push
https://help.github.com/articles/fork-a-repo for fetch and merge


[System] You are a helpful assistant.

[User] git-hash-object - Compute object ID and optionally create an object from a file

[Assistant]
SYNOPSIS git hash-object [-t <type>] [-w] [--path=<file> | --no-filters]
		[--stdin [--literally]] [--] <file>… git hash-object [-t <type>] [-w] --stdin-paths [--no-filters]


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --abbrev[=<n>]

[Assistant]
Instead of showing the full 40-byte hexadecimal object
name in diff-raw format output and diff-tree header
lines, show the shortest prefix that is at least <n> hexdigits long that uniquely refers the object.
In diff-patch output format, --full-index takes higher
precedence, i.e. if --full-index is specified, full blob
names will be shown regardless of --abbrev .
Non default number of digits can be specified with --abbrev=<n> .


[System] You are a helpful assistant.

[User] git-rebase - Reapply commits on top of another base tip  --onto <newbase>

[Assistant]
Starting point at which to create the new commits. If the --onto option is not specified, the starting point is <upstream> .  May be any valid commit, and not just an
existing branch name. As a special case, you may use "A...B" as a shortcut for the
merge base of A and B if there is exactly one merge base. You can
leave out at most one of A and B, in which case it defaults to HEAD.


[System] You are a helpful assistant.

[User]
How to remove all git origin and local tags?
How do you remove a git tag that has already been pushed?
Delete all git remote (origin) tags and Delete all git local tags.

[Assistant]
Delete All local tags. (Optional Recommended)
# Clears out all your local
git tag -d $(git tag -l)

Fetch remote All tags. (Optional Recommended)
# All remote tags give you a complete list of remote tags locally
git fetch

Delete All remote tags.
# Note: pushing once should be faster than multiple times
# Deletes the remote tags concerning the local
git push origin --delete $(git tag -l)

Delete All local tags.
# Deletes the local tags after fetch
git tag -d $(git tag -l)


[System] You are a helpful assistant.

[User]
How do I re-run Github Actions?

I see this on the Github web UI:

but it's not clear to me whether the disabled re-runs are a result of my .github/main.workflow configuration, or inherited from the Github Actions service.
Sample workflow below - I don't see anything obvious there that would disable re-runs.
workflow "Test, Lint" {
  on = "push"
  resolves = [
    "Test",
    "Lint",
    "Lint Format"
  ]
}

action "Install" {
  uses = "actions/npm@master"
  args = "install"
  secrets = ["SECRET_TOKEN"]
}

action "Test" {
  needs = "Install"
  uses = "actions/npm@master"
  args = "test"
  secrets = ["SECRET_TOKEN"]
}

action "Lint" {
  needs = "Install"
  uses = "actions/npm@master"
  args = "run lint"
  secrets = ["SECRET_TOKEN"]
}

action "Lint Format" {
  needs = "Install"
  uses = "actions/npm@master"
  args = "run lint:format"
  secrets = ["SECRET_TOKEN"]
}

[Assistant]
There are two situations:

On a failed build, from the docs

Optionally, if the run failed, to re-run the workflow, in the upper-right corner of the workflow, use the Re-run checks drop-down menu, and select Re-run all checks.

If your run did not fail, you have to trigger the event which your workflow runs on: .
In the most usual case of on: push, you can add an empty commit to poke GitHub actions:
git commit --allow-empty -m "trigger GitHub actions"
git push

This will add an empty commit (no files changed), and will trigger another push event on GitHub, and therefore trigger another workflow run.
This does, however, muck up the commit history.
You can later squash/remove these if you like, but it's perhaps not ideal.

This is an update to my original answer, which referred to GitHub Actions HCL-based v1, prior to the August 2019 YAML-based re-release.
@tuff got this right first, with @instantepiphany‘s caveat.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  none

[Assistant] Disable word diff again.


[System] You are a helpful assistant.

[User]
Reopen merge request in gitlab

Is there a way to reopen a merge request within Gitlab once it's been merged like there is with an issue?
In this example a merge request was merged before a code review and has been reverted, but it would be great to reopen the original merge request to keep the original history/discussions

[Assistant] There's Reopen merge request button in Gitlab (Checked with 10.3.4-ce, but appeared earlier). However it does absolutely nothing when pressed, even with commits added to the branch the merge request is tied with.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  --type <type>

[Assistant]
git config will ensure that any input or output is valid under the given
type constraint(s), and will canonicalize outgoing values in <type> 's
canonical form. Valid <type> 's include: bool : canonicalize values as either "true" or "false". int : canonicalize values as simple decimal numbers. An optional suffix of k , m , or g will cause the value to be multiplied by 1024, 1048576, or
1073741824 upon input. bool-or-int : canonicalize according to either bool or int , as described
above. path : canonicalize by expanding a leading ~ to the value of $HOME and ~user to the home directory for the specified user. This specifier has no
effect when setting the value (but you can use git config section.variable
~/ from the command line to let your shell do the expansion.) expiry-date : canonicalize by converting from a fixed or relative date-string
to a timestamp. This specifier has no effect when setting the value. color : When getting a value, canonicalize by converting to an ANSI color
escape sequence. When setting a value, a sanity-check is performed to ensure
that the given value is canonicalize-able as an ANSI color, but it is written
as-is.


[System] You are a helpful assistant.

[User]
Is it possible to git-checkout a single line instead of the entire file?
If I have modified several lines of a versioned file, is it possible to undo the changes of a line by command-line?
Just like I would do for an entire file with:
git checkout /path/to/file.extension

but doing something like, say
git checkout /path/to/file.extension --line 10

is this possible?

[Assistant] You can use git checkout -p to see each hunk individually and decide whether to check them out or leave them as is (and that takes an optional path argument as well if you'd like to narrow it down further).


[System] You are a helpful assistant.

[User] git-merge - Join two or more development histories together  merge.renames

[Assistant]
Whether Git detects renames.  If set to "false", rename detection
is disabled. If set to "true", basic rename detection is enabled.
Defaults to the value of diff.renames.


[System] You are a helpful assistant.

[User]
How to create development branch from master on GitHub

I created a repo on GitHub and only have a master branch so far. My local working copy is completely up to date with the remote/origin master on GitHub.
I now want to create a development branch on GitHub so that other people on my team can start pushing changes to development (instead of directly to master) and submit PRs, request code reviews, etc.
So I tried creating a new development branch locally and pushing it:
git checkout -b development
git push origin development:master

But git just says Everything up-to-date. So I ask:
If I'm current with master, how do I just create a remote development branch that contains an exact copy of master?

[Assistant]
Creating a git develop branch
You can list all of your current branches like this:
git branch -a

This shows all of the local and remote branches. Assuming you only have a single master branch, you'd see the following:
* master
  remotes/origin/master

The * means the current branch.
To create a new branch named develop, use the following command:
git checkout -b develop

The -b flag creates the branch. Listing the branches now should show:
* develop
  master
  remotes/origin/master

Changing branches
You shouldn't commit anything directly to the master branch. Instead do all your work on the develop branch and then merge develop into master whenever you have a new public release.
You are already in your develop branch, but if you weren't, the way to switch is as follows:
git checkout develop

That's the same way you create a branch but without the -b.
Making changes on develop
When making changes, add and commit as usual:
git add .
git commit -m "whatever"

The first time you push to your remote do it like so:
git push -u origin develop

The -u flag stands for --set-upstream. After the first time you only need to do it like this:
git push

Merging develop to master
Once your develop is ready to merge into master you can do it like so:
First switch to your local master branch:
git checkout master

To merge develop into master do the following:
git merge develop

Then push the changes in local master to the remote master:
git push

Done.
Deleting a branch
If you don't need the develop branch anymore, or you just want to delete it and start over, you can do the following:
Delete the remote develop branch:
git push -d origin develop

Then delete the local branch:
git branch -d develop

The -d means delete.


[System] You are a helpful assistant.

[User]
How do I refresh branches (local/remote) in Visual Studio when using Git?
Update
Upgrading to Visual Studio 2019 16.8.X has a new git workflow. This also includes a fetch button.

Summary
I am learning how to use Git with Visual Studio.  I recently did a pull request where the feature branch was deleted after the merge.  The feature branch still shows up in my local and remote branches in Visual Studio.  I know how to right click and delete the branch, this is a workaround as others on the team may complete a pull request on a branch that I have without me knowing it.  If they delete the branch afterwards I would not know they did so.
Question
How do you refresh Visual Studio branches with what is on Git?
What I expect
I would expect a button, link, or right click feature that on click checks for differences, if any are found it asks, "This branch no longer exists, would you like to remove it from Visual Studio?".
Tech Specs
I am using Visual Studio 2015 Enterprise (still seems to be a symptom of VS 2019 for versions lower than 16.8)
Additional Example
This could be another question, but it fits so well here.  I just noticed that if I create a branch (say in one VM and look at the same repo with another), Visual Studio does not have a git fetch option to update the branch list.  The refresh button at the top does not seem to do anything.  As soon as I run git fetch in a bash, visual studio has the new branch.  I would expect the refresh to take care of this.

[Assistant]
If the branch has been deleted on the server side, try in command line (since such a "button" doesn't seem to exist directly in Visual Studio):
git remote prune origin --dry-run

(remove the --dry-run option to actually delete the local branches)
Delete the corresponding local branch as well git branch -d aBranch.
Then restart your Visual Studio, and check it picks up the updated branch list. (comments mention you don't have to restart/refresh VS)
Note: I mentioned before in 2013 the configuration
git config remote.origin.prune true

That would automate that process, and seems to be supported by Visual Studio, as mentioned below by yaniv.

On VSCode, try also to activate the setting "Git: Prune on Fetch"
"git.pruneOnFetch": true


[System] You are a helpful assistant.

[User] git-rebase - Reapply commits on top of another base tip  renormalize

[Assistant]
This runs a virtual check-out and check-in of all three stages
of a file when resolving a three-way merge.  This option is
meant to be used when merging branches with different clean
filters or end-of-line normalization rules.  See "Merging
branches with differing checkin/checkout attributes" in gitattributes for details.


[System] You are a helpful assistant.

[User]
Github (SSH) via public WIFI, port 22 blocked
I'm currently on a public WIFI spot and I'm unable to use SSH (they probably blocked that port). However, I need that connection to do a git push.
➜ ssh -T [email protected]
ssh: connect to host github.com port 22: Connection refused

Is it possible to bypass this restriction by setting up a SSH tunnel via port 80 and tell github push to use that connection? How to do that? I'm on OSX (lion). This must be a common problem?

[Assistant]
Try this:
$ vim ~/.ssh/config

Add
Host github.com
  Hostname ssh.github.com
  Port 443

Source: https://help.github.com/articles/using-ssh-over-the-https-port


[System] You are a helpful assistant.

[User]
How do I ignore file extensions in git regardless of case?
I want to tell git to ignore e.g. jpg files regardless of how the extension is written.
e.g.

*.jpg

should ignore

.jpg, .JPG., .Jpg

etc.
Is that possible without telling git to ignore case altogether?

[Assistant]
Git ignore understands glob pattern, so you can use this
*.[jJ][pP][gG]


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  instaweb.port

[Assistant] The port number to bind the gitweb httpd to. See git-instaweb .


[System] You are a helpful assistant.

[User] git-log - Show commit logs  zebra

[Assistant]
Blocks of moved text are detected as in blocks mode. The blocks
are painted using either the color.diff.{old,new}Moved color or color.diff.{old,new}MovedAlternative . The change between
the two colors indicates that a new block was detected.


[System] You are a helpful assistant.

[User]
Move a repository from Github to Gitlab

Is there a way to move an entire repository from Github to GitLab?
For the code itself, this would be a simple matter of creating a new repo on GitLab and pushing to it.
Wiki pages live in a separate branch on Github and are managed with Git mechanisms; AFAIK the same goes for GitLab. Same story for pages.
That leaves issues and merge requests as the main open points. Is there a way to copy those from Github to GitLab, at least in the state they were in at the time of the migration?
Github offers an export ferature, and GitLab has an import feature which can import a Github repository—do any of these help with the above?

[Assistant]
GitLab’s import feature has worked quite nicely.

On https://gitlab.com (make sure you are logged in), you will get a list of your projects. Click New Project.
Open the Import Project tab, and click Github.
If you have not granted Gitlab authorization to access your Github account, you will be prompted to do so now.
A list of your Github repos will appear. For each repo you wish to import, choose the namespace (your personal one or that of any of your organizations, if any) and change the project name if you wish. (Default is to import to your personal namespace and use the same repo name as on Github.) Then click Import next to the repo you wish to import.

Import will take a couple of minutes. When it finishes, you will get your entire repo, including wiki, issues and merge requests. Issues and merge requests will retain ticket numbers as on Github, and labels also seem to get migrated.
Github Pages do not seem to get migrated automatically. This requires some manual steps. For purely static content (no SSG), with content stored in the gh-pages branch, the process is as follows:

Switch to your gh-pages branch.
Create a new folder public and move all content there.
Commit your changes.
Switch back to master and merge gh-pages (so that your content now resides on a separate folder in master rather than its own branch).
On your project’s main page, click Add CI/CD. This will create a new .gitlab-ci.yml file; add the following content and commit:

image: alpine:latest

pages:
  stage: deploy
  script:
  - echo 'Nothing to do...'
  artifacts:
    paths:
    - public
  only:
  - master

This will take another few minutes. Navigate to Settings > Pages and click the link to your pages.
Github has multiple options for storing web content; the above may also work for others with slight modifications.


[System] You are a helpful assistant.

[User]
Vim for Windows - What do I type to save and exit from a file?
Using Windows XP I accidentally typed git commit -a instead of git commit -am "My commit message", and now I'm viewing my CMD prompt filled with the file version of my commit message ("Please enter the commit message for your..."). I've added my message to the top, but now I can't figure out how to save and leave. I tried to press Ctrl + W + Q, but it doesn't do anything, but add ^ where the cursor is.
I also tried Esc first, and then Ctrl + W + Q, but it says No write since last change (add ! to override).

[Assistant]
Press ESC to make sure you are out of the edit mode and then type:
:wq


[System] You are a helpful assistant.

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

[Assistant] reflog identity email


[System] You are a helpful assistant.

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

[Assistant]
Generate diffs with <n> lines of context instead of the default
of 3. This value is overridden by the -U option.


[System] You are a helpful assistant.

[User] gitsubmodules - Mounting one repository inside another

[Assistant]
The configuration of submodules Submodule operations can be configured using the following mechanisms
(from highest to lowest precedence): The command line for those commands that support taking submodules
as part of their pathspecs. Most commands have a boolean flag --recurse-submodules which specifies whether to recurse into submodules.
Examples are grep and checkout .
Some commands take enums, such as fetch and push , where you can
specify how submodules are affected. The configuration inside the submodule. This includes $GIT_DIR/config in the submodule, but also settings in the tree such as a .gitattributes or .gitignore files that specify behavior of commands inside the
submodule. For example an effect from the submodule’s .gitignore file
would be observed when you run git status --ignore-submodules=none in
the superproject. This collects information from the submodule’s working
directory by running status in the submodule while paying attention
to the .gitignore file of the submodule. The submodule’s $GIT_DIR/config file would come into play when running git push --recurse-submodules=check in the superproject, as this would
check if the submodule has any changes not published to any remote. The
remotes are configured in the submodule as usual in the $GIT_DIR/config file. The configuration file $GIT_DIR/config in the superproject.
Git only recurses into active submodules (see "ACTIVE SUBMODULES"
section below). If the submodule is not yet initialized, then the configuration
inside the submodule does not exist yet, so where to
obtain the submodule from is configured here for example. The .gitmodules file inside the superproject. A project usually
uses this file to suggest defaults for the upstream collection
of repositories for the mapping that is required between a
submodule’s name and its path. This file mainly serves as the mapping between the name and path of submodules
in the superproject, such that the submodule’s Git directory can be
located. If the submodule has never been initialized, this is the only place
where submodule configuration is found. It serves as the last fallback
to specify where to obtain the submodule from.


[System] You are a helpful assistant.

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

[Assistant]
If no --file option is provided to git config , use the file
given by GIT_CONFIG as if it were provided via --file . This
variable has no effect on other Git commands, and is mostly for
historical compatibility; there is generally no reason to use it
instead of the --file option.


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  --submodule[=<format>]

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


[System] You are a helpful assistant.

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

[Assistant]
Reverses the meaning of the ^ prefix (or lack thereof)
for all following revision specifiers, up to the next --not .
When used on the command line before --stdin, the revisions passed
through stdin will not be affected by it. Conversely, when passed
via standard input, the revisions passed on the command line will
not be affected by it.


[System] You are a helpful assistant.

[User]
How to disable Create Project permission for users by default in GitLab?

I am using the Omnibus GitLab CE system with LDAP authentication.
Because of LDAP authentication, anyone in my company can sign in to GitLab and a new GitLab user account associated with this user is created (according to my understanding).
I want to modify it so that by default this new user (who can automatically sign in based on his LDAP credentials) cannot create new projects.
Then, I as the admin, will probably handle most new project creation.
I might give the Create Project permission to a few special users.

[Assistant]
In newer versions of GitLab >= v7.8 …
This is not a setting in config/gitlab.yml but rather in the GUI for admins.
Simply navigate to https://___[your GitLab URL]___/admin/application_settings/general#js-account-settings, and set Default projects limit to 0.
You can then access individual users's project limit at https://___[your GitLab URL]___/admin/users.

See GitLab's update docs for more settings changed between v7.7 and v7.8.
git diff origin/7-7-stable:config/gitlab.yml.example origin/7-8-stable:config/gitlab.yml.example


[System] You are a helpful assistant.

[User] git-rebase - Reapply commits on top of another base tip  ours

[Assistant]
This option forces conflicting hunks to be auto-resolved cleanly by
favoring our version.  Changes from the other tree that do not
conflict with our side are reflected in the merge result.
For a binary file, the entire contents are taken from our side. This should not be confused with the ours merge strategy, which does not
even look at what the other tree contains at all.  It discards everything
the other tree did, declaring our history contains all that happened in it.


[System] You are a helpful assistant.

[User] git-branch - List, create, or delete branches  <start-point>

[Assistant]
The new branch head will point to this commit.  It may be
given as a branch name, a commit-id, or a tag.  If this
option is omitted, the current HEAD will be used instead.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  format.signatureFile

[Assistant]
Works just like format.signature except the contents of the
file specified by this variable will be used as the signature.


[System] You are a helpful assistant.

[User]
GitLab: extend `!reference` with extra values in `variables`

How can one use !reference in variables block and then extend the list of entries?
For example, I want to be able to do something like
variables:
  !reference [.common_variables, variables]
  FOO: "bar"

At the moment I get an error in the GitLab linter:

This GitLab CI configuration is invalid: (): did not find expected key while parsing a block mapping at line 1 column 1

P.S. Note that this question is specifically about !reference.

Yaml anchors are out of scope of this question, as I want to place .common_variables into a separate file that I include in my pipeline.
extends: mechanism is out of scope of this question. It does work, but it has a weird behaviour that one also gets an extends variable in the environment, see GitLab: use `extends` in `variables`

[Assistant]
variables: !reference [.common_variables, variables]

Is the correct way to reference, however gitlab yml structure will not support additional definitions after the !reference keyword.
My advice would be to have a more specific definition in your variables file that uses anchors to share the common varaibles.
e.g:
in 'variables.gitlab-ci.yml':
.common_variables: &common_variables
     COMMON_VAR: value

.variables:Example-job
    variables:
        <<: *common_variables
        FOO: "bar"

in '.gitlab.ci.yml':
Example-job:
    variables: !reference [".variables:Example-job", "variables"]
    script:
        ...


[System] You are a helpful assistant.

[User]
Git push failed with error: “GitLab: Author not member of team”

git push failed with the following message:
remote: GitLab: Author '`[email protected]`' is not a member of team

My #git config user.name and #git config user.email are set as:
#git config user.name
Sam Logan

#git config user.email
[email protected]

My hostname is logath-T460.
I am not sure why git push uses my localhostname with the Author.  Any clue how to resolve this issue?

[Assistant]
It's not git push that's using your username + hostname, it's git commit.
By default, if you did not set user.name and user.email BEFORE making a commit, git will get it from your computer name and hostname. It would also have shown you a warning like this:
Committer: user1234 <[email protected]>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email [email protected]

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1.txt

When you do git push, it would just use whatever was set as the commit author and push it to the remote repo.
What I think happened, is that you already committed BEFORE you set the correct user.name and user.email settings. So those commits you're trying to push already has that invalid user details "[email protected]" saved as the commit author.
What you need to do then is to update the author of the previous commits.
First, make sure to properly set the user.name and user.email config (--global or --local to the repo), otherwise known as your Git identity.
git config --global user.name "yourname"
git config --global user.email "[email protected]"

Set it now to the correct identity that matches the user account of your Gitlab repo.
Then use --reset-author on those commits.

To modify the author of only the most recent commit:
git commit --amend --reset-author --no-edit

To modify the author of multiple past commits:
(reference: How to amend several commits in Git to change author)
git rebase -i HEAD~N -x "git commit --amend --reset-author --no-edit"

where N is the number of previous commits you need to update. The rebase -i will show a command line editor to show you the changes, and --reset-author will use your current user.* settings. Just save and quit to apply to changes.

After that, git push should now work.


[System] You are a helpful assistant.

[User] git-gc - Cleanup unnecessary files and optimize the local repository

[Assistant] NAME git-gc - Cleanup unnecessary files and optimize the local repository


[System] You are a helpful assistant.

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

[Assistant]
The filter that will be applied when fetching from this	promisor remote.
Changing or clearing this value will only affect fetches for new commits.
To fetch associated objects for commits already present in the local object
database, use the --refetch option of git-fetch .


[System] You are a helpful assistant.

[User]
GitHub Error Message - Permission denied (publickey)
Anybody seen this error and know what to do?
I'm using the terminal, I'm in the root, the GitHub repository exists and I don't know what to do now.
> git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

[Assistant]
GitHub isn't able to authenticate you.  So, either you aren't setup with an SSH key, because you haven't set one up on your machine, or your key isn't associated with your GitHub account.
You can also use the HTTPS URL instead of the SSH/git URL to avoid having to deal with SSH keys.  This is GitHub's recommended method.
Further, GitHub has a help page specifically for that error message, and explains in more detail everything you could check.
To solve it:

You should have a public key in your home directory, thus print the content of your public key, in Linux distro run for example cat ~/.ssh/id_rsa.pub (if the prior doesn't work, check the keys inside ~/.ssh/ with .pub extension)

Add the content of such a public key to your Github account: click your profile photo -> Settings-> SSH and GPG keys -> New SSH key or Add SSH key


[System] You are a helpful assistant.

[User] gitrevisions - Specifying revisions and ranges for Git  AUTO_MERGE

[Assistant]
records a tree object corresponding to the state the ort merge strategy wrote to the working tree when a merge operation
resulted in conflicts.


[System] You are a helpful assistant.

[User]
Differences between git branches using Visual Studio
I'm trying to understand how to compare branches or commits using VS 2015.
Using other Git programs, I can easily compare versions, but I can't see how it's done in VS.
Can anyone help?

[Assistant]
To compare a specific object (solution, project, source file,...) in Microsoft Visual Studio (using MVS2015):

Locate the object in the Solution Explorer, and bring up the context menu (right-click): select "View History...". This brings up the History window for this object, with all the commits where the object changed (from any branch).
Multi-select the two commits that you want to compare (left-click on the first one, Ctrl-left-click on the second one).
Now bring up the context menu on either of the selected commits (right_click): select "Compare...". This brings up the Diff window for the object in the respective commits (with the differences highlighted in red -lines removed from first commit- or green -lines added in second commit). You can use the scroll bar in the Diff window, or the "Previous Difference" and "Next Difference" button in the ribbon to go between the differences of the object.

I am not sure that there is a way to compare ALL the items in two different commits (I just invoke GitKraken -free for non-commercial purposes- or any other GUI for git on my local repo). Gitkraken is amazingly simple though: select any two commits, and all the differences between those commits are available at your fingertips.


[System] You are a helpful assistant.

[User]
Is there a way to limit the amount of memory that "git gc" uses?
I'm hosting a git repo on a shared host.  My repo necessarily has a couple of very large files in it, and every time I try to run "git gc" on the repo now, my process gets killed by the shared hosting provider for using too much memory.  Is there a way to limit the amount of memory that git gc can consume?  My hope would be that it can trade memory usage for speed and just take a little longer to do its work.

[Assistant]
I used instructions from this link.  Same idea as Charles Baileys suggested.
A copy of the commands is here:
git config --global pack.windowMemory "100m"
git config --global pack.packSizeLimit "100m"
git config --global pack.threads "1"

This worked for me on hostgator with shared hosting account.


[System] You are a helpful assistant.

[User]
Github: Mirroring gh-pages to master
I'm developing a jQuery plugin that's being hosting on GitHub. It has a demo included of which I'm manually copying and pushing to the branch gh-pages, what I'd like to do is have it so when I push a change to master it is automatically pushed to gh-pages, or at least a setup where they are mirrored.
I've already seen this question but not sure if it really answers my question with regard to these requirements:

I use Tower, I don't mind using the terminal (Mac) to make changes to config, so long as the solution works with this GUI.
I only want this 'mirroring' on certain repos, not on all of them on my machine.

Cheers

[Assistant]
Add the following 2 lines to the [remote "origin"] section of .git/config:
push = +refs/heads/master:refs/heads/gh-pages
push = +refs/heads/master:refs/heads/master

Every time you push it will automatically push master to gh-pages as well.
I'm using this for the jQuery Lifestream project.


[System] You are a helpful assistant.

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

[Assistant] ref names, like the --decorate option of git-log


[System] You are a helpful assistant.

[User]
Git: copy all files in a directory from another branch
How do I copy all files in a directory from another branch? I can list all of the files in that directory by doing
git ls-tree master:dirname

I can then copy all of the files individually by doing
git checkout master -- dirname/filename

However, using wildcards has so far been a total fail.  This does nothing:
git checkout master -- dirname/*.png

Though I guess I can use a bash script to do that, there has to be an easier way, right?

[Assistant]
As you are not trying to move the files around in the tree, you should be able to just checkout the directory:
git checkout master -- dirname


[System] You are a helpful assistant.

[User]
Git: How to commit a manually deleted file? [duplicate]

This question already has answers here:

Delete files from git index when they are already deleted from fs

                                (7 answers)

Staging Deleted files

                                (10 answers)

Closed 11 years ago.

In my git repository I manually deleted a file(rm) after moving it to another folder. I than committed all the changes to my repo but now when I do git status .
ronnie@ronnie:/home/github/Vimfiles/Vim$ git status .
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    plugin/dwm.vim
#
no changes added to commit (use "git add" and/or "git commit -a")

Now, how should I commit so that dwm.vim is deleted from the plugin folder in my remote repo. I know that I have to use git add && git commit but I have no file to commit/add because /plugin/dwm.vim is already deleted.

[Assistant]
The answer's here, I think.
It's better if you do git rm <fileName>, though.


[System] You are a helpful assistant.

[User]
How to solve git merge error "Swap file .MERGE_MSG.swp already exists"
When I pull:
E325: ATTENTION
Found a swap file by the name "~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp"
          owned by: username   dated: Wed Dec 14 12:28:45 2016
         file name: ~username/Documents/Sites/recipegenerator/.git/MERGE_MSG
          modified: YES
         user name: username   host name: Users-MacBook-Pro.local
        process ID: 33747
While opening file "/Users/larsvanurk/Documents/Sites/recipegenerator/.git/MERGE_MSG"
             dated: Thu Dec 22 14:06:17 2016
      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 /Users/username/Documents/Sites/recipegenerator/.git/MERGE_MSG"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/Users/username/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp"
    to avoid this message.

Swap file "~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp" already exists!

When I push:
To  https://github.com/nickname/recipegenerator.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/nickname/recipegenerator.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Please help :C Idk what to do. I can't push or pull. I tried pretty much everything I could think of. I also tried: git merge --abort. The thing is when I do that, I can't seem to find my conflict that I should resolve.

[Assistant]
It's a message from VIM which apparently you are using as the text editor in git. Have you tried reading and following these two (1) (2) points? One of them will be probably true, and will let you solve this issue.
First of all, check that MERGE_MSG file (not MERGE_MSG.swp), and see if it exists and what's inside. Most likely it's trash or a temporary file that can be safely deleted. Judging from the name, it's probably the file name used as a temporary text editing area for merge commit messages.
Then, since you use VIM, when VIM starts, it tries to create a swap file for its own internal needs. The error message says it's ~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp. Often, you can simply delete such swap files, especially if they are old or unexpected. However, if recently some merge-commit-message-editing session has crashed and if you had a lot of creative text you don't want to lose - then don't delete it and recover that swap instead, as described in (2) in the error message.
However, since you don't know what is going on and you haven't said anything about losing some text you wrote, and since it's probably just a MERGE_MSG that was auto-generated anyways, I suppose you can:
git merge --abort
rm ~/Documents/Sites/recipegenerator/.git/.MERGE_MSG.swp

and try what you were doing once again.
Also, it's good to check the hint mentioned in (1) in error message. Check with ps or whatever else for any open VIM sessions that could be currently editing that MERGE_MSG. If you spot any, then, well, get to them and either finish editing, or make them quit (escape, :q!, enter) (vim will cleanup swaps on quitting), or terminate them (kill them, but then you need to remove swap files manually).


[System] You are a helpful assistant.

[User] git-format-patch - Prepare patches for e-mail submission  --dst-prefix=<prefix>

[Assistant] Show the given destination prefix instead of "b/".


[System] You are a helpful assistant.

[User]
How can I push my existing Git repository to Team Foundation Service
Microsoft now has support for Git repositories on their Team Foundation Service. I have an account on Team Foundation Service, and I'd like to push my existing Git repository to a project there.
Whenever I try to do searches, I keep finding things like TFS-GIT, or GIT-TF. I'm pretty sure I don't want those, as I think those change to the Team Foundation Server model for code repositories, and that's not what I want.
Specifically, I have an existing Git repository that I want to push to TFService.

[Assistant]
Okay, I was apparently overcomplicating this. Here's what I did.

Created a new project in TFService
Connected to that project in Visual Studio
Cloned that project in Visual Studio
git pull c:\source\oldGitProject

That was it, it pulled all of the changes from the old location, and I could push that up to TFService easily.


[System] You are a helpful assistant.

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

[Assistant]
BUGS Using --recurse-submodules can only fetch new commits in submodules that are
present locally e.g. in $GIT_DIR/modules/ . If the upstream adds a new
submodule, that submodule cannot be fetched until it is cloned e.g. by git
submodule update . This is expected to be fixed in a future Git version.