[System] You are a helpful assistant.

[User]
Your repository has no remotes configured to push to
I am using Visual Studio Code and running into the message below while trying to check in.
Your repository has no remotes configured to push to.

This is right after I upgrade from the April version on the Macintosh to the May version.  I upgraded since I was getting an infinite progress bar during a git update.  Does anybody have any ideas how to fix this?  I have used the command line to verify that I do indeed have remotes configured.  Can't post them here since it will show inter company info :(.  Please help.

[Assistant]
Check the Github adding a remote article official doc which have better code highlighting and infos
but if you are an experienced user, just check out below commands and note that only the first command is required and second one is just for verifying and will return related repo details.
git remote add origin https://github.com/user/repo.git

git remote -v

Git  Remote add Command dissection

params:

remote name: origin (a default name for a remote Repo in Git )
remote url: https://github.com/user/repo.git (in this example)


[System] You are a helpful assistant.

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

[Assistant] (ERROR) Unable to read .gitmodules blob.


[System] You are a helpful assistant.

[User]
.gitignore exclude files in directory but not certain directories
application/cache/*
application/cache/folder/*
application/cache/folder/onemorefolder/*

This doesn't seem to be working. When I clone the project, there is no "application/cache" folder or "application/cache/folder" folder, etc...
I'd like if files in the cache folders weren't cached but folders were, so that the folders permissions transfer and exist.

[Assistant]
Git doesn't track folders, only files, so if you ignore everything in a folder, Git won't have anything to track. You can add a .gitignore file to each directory (application/cache, application/cache/folder, application/cache/folder/onemorefolder/) with the following contents:
*
!.gitignore

Then, you can add those directories, and only the .gitignore file in each directory will get added -- but this means the directories will now be tracked (i.e., created when cloning).


[System] You are a helpful assistant.

[User]
How can I graph the Lines of Code history for git repo?
Basically I want to get the number of lines-of-code in the repository after each commit.
The only (really crappy) ways I have found is to use git filter-branch to run wc -l *, and a script that runs git reset --hard on each commit, then runs wc -l
To make it a bit clearer, when the tool is run, it would output the lines of code of the very first commit, then the second and so on. This is what I want the tool to output (as an example):
me@something:~/$ gitsloc --branch master
10
48
153
450
1734
1542

I've played around with the ruby 'git' library, but the closest I found was using the .lines() method on a diff, which seems like it should give the added lines (but does not: it returns 0 when you delete lines for example)
require 'rubygems'
require 'git'

total = 0
g = Git.open(working_dir = '/Users/dbr/Desktop/code_projects/tvdb_api')

last = nil
g.log.each do |cur|
  diff = g.diff(last, cur)
  total = total + diff.lines
  puts total
  last = cur
end

[Assistant] You might also consider gitstats, which generates this graph as an html file.


[System] You are a helpful assistant.

[User]
How to review a pull request in IntelliJ IDEA?
We are using git, Bitbucket, and IntelliJ IDEA. The project is mainly written in Java and Groovy.
Is there a good way to review pull requests right from IntelliJ?

[Assistant]
Most up-to-date information (March 2021)
Now, IntelliJ 2020.2 fully supports reviewing Pull Requests.

Accessing the feature
You can either navigate to: Main menu > VCS > Git > View Pull Requests.

Or it might be in your left "side-menu" (here the third option from the top):

Further information
It seems to be mostly an integration for GitHub (source):

Now the entire GitHub pull request workflow can be done directly from IntelliJ IDEA. It’s possible to browse, assign, manage, and even merge pull requests, view the timeline and inline comments, submit comments and reviews, and accept changes.

A more in-depth description of all the VCS-related features introduced can be found here:

Full GitHub Pull Requests support
We are excited to announce that IntelliJ IDEA 2020.2 will come with full support for GitHub Pull Requests!
We introduced initial support for GitHub Pull Requests with v2018.3, and we’ve been enhancing this functionality ever since. Previously, the IDE had some useful features, such as the GitHub tool window with a list of all pull requests associated with the repository, the Timeline view for a pull request, which opens in the editor, and the ability to view comments in diffs and create comments of your own. But those features were mostly for viewing pull requests and not for interacting with them.
With the upcoming IntelliJ IDEA 2020.2, you’ll be able to browse, assign, manage, and even merge pull requests, view the timeline and in-line comments, submit comments and reviews, and accept changes.
You no longer need to switch between the browser and your IDE. The entire Pull Request workflow can now be completed from within IntelliJ IDEA!

More previews
And two more sneak-peaks for the Review and Merge:

Creating PRs
Moreover, as of 2021.1, you can create Pull Requests, too:


[System] You are a helpful assistant.

[User] git-blame - Show what revision and author last modified each line of a file  --encoding=<encoding>

[Assistant]
Specifies the encoding used to output author names
and commit summaries. Setting it to none makes blame
output unconverted data. For more information see the
discussion about encoding in the git-log manual page.


[System] You are a helpful assistant.

[User]
Git: how to get all the files changed and new files in a folder or zip?
As my question says, after changing files and adding new files in my repository, I normally commit files with git, but sometimes I need all the modified / changed files copied to a folder for organizing-myself reasons.
Any option?

[Assistant]
Assuming you mean you haven't yet committed, and want to package up all of the files that currently have local modifications (but not completely new files), you can get the list of modified files with git ls-files --modified. If you want the files which were changed by the last commit, you could use git diff --name-only HEAD^. Where you go from there is up to you. Examples:
zip modified-files.zip $(git ls-files --modified)
cp --parents $(git ls-files --modified) ../modified-files # Linux
rsync -R $(git ls-files --modified) ../modified-files # macOS

Note that this is using the versions of files in the working tree currently.
If you have spaces in filenames, you'll have to go to a little more trouble.
(Of course, depending on what you're really trying to do, you might be looking for git stash, which stashes away all modified files and leaves you with a clean working tree, or you could simply want to make a temporary branch to commit to.)


[System] You are a helpful assistant.

[User]
why I have HTTP 403 from repo spring?

I have a jhipster project which deploy on heroku with gitlab since several months
Since yesterday, I can not deploy new version because I have this error
FAILURE: Build failed with an exception.
32 * What went wrong:
33 A problem occurred configuring root project 'yvidya'.
34 > Could not resolve all artifacts for configuration ':classpath'.
35    > Could not resolve io.spring.gradle:propdeps-plugin:0.0.10.RELEASE.
36      Required by:
37          project :
38       > Could not resolve io.spring.gradle:propdeps-plugin:0.0.10.RELEASE.
39          > Could not get resource 'http://repo.spring.io/plugins-    release/io/spring/gradle/propdeps-plugin/0.0.10.RELEASE/propdeps-plugin-0.0.10.RELEASE.pom'.
40             > Could not GET 'http://repo.spring.io/plugins-release/io/spring/gradle/propdeps-plugin/0.0.10.RELEASE/propdeps-plugin-0.0.10.RELEASE.pom'. Received status code 403 from server:     Forbidden

Anyone know why this error? and how solve it?

[Assistant] Open your build.gradle file and replace the spring maven repository URL from http with https


[System] You are a helpful assistant.

[User] git - the stupid content tracker  GIT_DEFAULT_REF_FORMAT

[Assistant]
If this variable is set, the default reference backend format for new
repositories will be set to this value. The default is "files".
See --ref-format in git-init .


[System] You are a helpful assistant.

[User]
Git: Pull from other remote
I have created a fork from a project on GitHub.
How can I now pull changes from the project that I forked from?

[Assistant]
git pull is really just a shorthand for git pull <remote> <branchname>, in most cases it's equivalent to git pull origin master. You will need to add another remote and pull explicitly from it. This page describes it in detail:
http://help.github.com/forking/


[System] You are a helpful assistant.

[User]
How to verify ssh key on Gitlab.com

I'm setting up a SSH key for the first time on Gitlab.com. I'm stuck at verifying that you can connect: ssh -T [email protected].
The gitlab.example.com you are supposed to replace with your Gitlab instance url but I keep getting "ssh: Could not resolve hostname : Name or service not known".
I'm using the Gitlab SaaS solution and have tried various formats, such as:
ssh -T [email protected]/my-workspace-name
ssh -T [email protected]:my-workspace-name
ssh -T [email protected]/my-workspace-name/project-name

What is the correct format that should work?

[Assistant]
Correct format is ssh -T [email protected].
my-workspace-name is not part of the instance url.


[System] You are a helpful assistant.

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

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


[System] You are a helpful assistant.

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

[Assistant] Prepare patches for e-mail submission


[System] You are a helpful assistant.

[User]
How to register a local git package in Bower?
How can I register a local git package in bower?
My current component.json is as follows
{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1"
  }
}

However I also would like to add a package I have created at C:/mypackage which is a git repository with versions tagged.
When I do bower install --save C:/mypackage it properly adds it to project but it doesn't add it to my component.json.
I am trying bower register mypackage C:/mypackage but it keeps giving me
bower error Incorrect format

What am I doing wrong?

[Assistant]
Option 1: Public Bower registration
Bower is built mostly to share public (client-side) code in a "non-opinionated" manner. The primary use case, then, is to have a publicly accessible repository (on GitHub) that is registerd with a name and git repository url. I just did this myself:
bower register linksoup git://github.com/automatonic/linksoup

This is just telling the bower server that when you install linksoup to go and grab the code at the git://github.com/automatonic/linksoup repository, and put it in the local project's component directory.
If this is what you want to do, then just set up a repository on github/etc., push your code there, and then register with the resulting repository info.
Option 2: Private dependency
There are many reasons not to post your code at a publicly accessible repository. It may not be open source, etc. if your mypackage code is not meant to be public, then you should probably not be registering it on the public bower server... Further, even if you could register a local directory, it would only work on your machine...which defeats the purpose of sharing the code via bower.
If you just want to have bower manage a local, private dependency, then I am going to riff off of blockhead's solution:
{
  "name": "myproject",
  "version": "1.0.0",
  "dependencies": {
    "jquery": "1.8.0",
    "twitter/bootstrap": "2.1.1",
    "mypackage": "file:///path/to/mypackage/.git"
  }
}

This is just saying that myproject needs mypackage, and to use git clone to retrieve it. My guess is that this can use anything git can understand (including local repositories). But you should note that this may run into problems for anyone else working on this code that cannot access your local path.
Best Guess
It looks to me as if you may have assumed that bower register was a local operation (telling bower how to find a dependency via some sort of local registry). As far as I can tell, this is only a remote and public registration, which is why this is unsupported.
You may also be looking for a way to do something like a link operation with npm. That is, work on a dependency module without always having your dev cycle include a publish.
A little detail about how many people are involved and what you were trying to accomplish would facilitate a more targeted answer.


[System] You are a helpful assistant.

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

[Assistant]
If set to "warn", git rebase -i will print a warning if some
commits are removed (e.g. a line was deleted), however the
rebase will still proceed. If set to "error", it will print
the previous warning and stop the rebase, git rebase
--edit-todo can then be used to correct the error. If set to
"ignore", no checking is done.
To drop a commit without warning or error, use the drop command in the todo list.
Defaults to "ignore".


[System] You are a helpful assistant.

[User]
How to deal with Git "Could not read" error
I am getting this error in my git repository:
22:09:15 $ git status
# On branch master
error: Could not read 8124cc15c63be92d534e4cdfa33c38d54deee122
error: unable to read tree object HEAD
nothing to commit (working directory clean)

A Google search for error: unable to read tree object HEAD doesn't result in much help, this error seems to be very rare. I am not sure how to deal with it. Could it be a hard drive failure?
Edit:
The output of git fsck is the following:
broken link from  commit 607328dc80e4901a55b95c683d4fbf43e6df28bf
              to    tree 8124cc15c63be92d534e4cdfa33c38d54deee122
missing tree 8124cc15c63be92d534e4cdfa33c38d54deee122
dangling tree 56b5d4a5e429d251582ec927bca7ef1225510c41
dangling tree 0259d2d38b18b6136bb6070fb41faf3624453cc6

[Assistant]
On a "broken link" message, you could follow the GitFaq recommendations:

back up all your state so that anything you do is re-doable if you corrupt things more!
explode any corrupt pack-files

See "man git-unpack-objects", and in particular the "-r" flag.
  Also, please realize that it only unpacks objects that aren't already available, so you need to move the pack-file away from its normal location first (otherwise git-unpack-objects will find all objects that are in the pack-file in the pack-file itself, and not unpack anything at all)

replace any broken and/or missing objects

This is the challenging part.
  Sometimes (hopefully often!) you can find the missing objects in other copies of the repositories.
  At other times, you may need to try to find the data some other way (for example, maybe your checked-out copy contains the file content that when hashed will be the missing object?).

make sure everything is happy with "git fsck --full"
repack everything to get back to an efficient state again

Notes:

missing objects can also be related to alternate (when you share objects between repositories) with git alternates (even though that can be risky).
The JGit/Egit eclipse plugin is also known to have a few issues.
(Update February 2012: those plugins have come a long way and are now quite stable)

Update July 2016 (7 years laters), with Git 2.10 soon to be released, you now have:
git fsck --name-objects

It helps naming the origin of those broken links
See "How to fix git error broken link from tree to tree?" for more.


[System] You are a helpful assistant.

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

[Assistant]
A list of colors, separated by commas, that can be used to draw
history lines in git log --graph .


[System] You are a helpful assistant.

[User]
Performing VCS Refresh... (Takes too long or never finishes)
What is the fix for the issue when trying to commit from IntelliJ:

This windows either takes too long or does not finished at all. What is the work around so I can commit again from IntelliJ

[Assistant]
In IntelliJ navigate to:

File > Invalidate Caches / Restart...

and select the highlighted:

Invalidate and Restart


[System] You are a helpful assistant.

[User]
Is there a tool to have git show "detached heads" in a graph?
I often refer to git log --graph --decorate --oneline --all --full-history to see the current state of my branches, but it does not show detached heads/anonymous branches. Is there a way to get detached heads to appear in this graph?
I know that git reflog exists, but that is pretty hard to read since there is no structure - all you have to go on is the commit message, which still may be WIP if I haven't finished the commit yet.
Some background (this is not necessary to answer the question, but will help explain the motivation for it): I'm a Mercurial user and my workflow involves a lot of anonymous branching. I tend to make use of hg heads a lot to check out these heads, and often hg rebase to separate or combine series of commits based on what makes sense for the purpose of an easy to understand code review.
While I'm getting used to using git I often find myself with detached heads when, for example, I rebase some commits from a branch to make a new branch. Finding these detached heads is annoying with git reflog, and to be honest it's a little scary that they just disappear from the usual git log. I've even forgotten about old commits this way, and have had to dig them out of git reflog a day or two later. In Mercurial those commits would remain as an anonymous head, and I would be reminded that I need to finish them off.

[Assistant]
It sounds like you're trying to use a workflow that doesn't quite match the way git works.
First of all, a "detached head" in git isn't the same as Mercurial's concept of a "head". Git has exactly one HEAD, which is just the currently checked-out commit. "Detached" just means that you don't currently have a branch checked out. So when you create a commit, it won't be associated with a branch, and it'll be lost when you checkout a different commit.
In Git, every commit that you care about should be reachable from some branch. There's no such thing as an "anonymous branch", which is why git warns you when committing on a detached head. Committing on a detached head is like allocating an object and then throwing away the pointer; it's possible, but almost never what you want to do. Remember, branches in git are lightweight and can be ephemeral. Just create a branch before committing so that you can find your commits again.
All that being said, if you really want to see the structure of your repository, including commits that are only referenced from reflogs, you can use:
git log --graph --decorate $(git rev-list -g --all)


[System] You are a helpful assistant.

[User]
Understanding Gitlab CI tags

I've read documentation, some articles and you might call me dumb, but this is my first time working with a concept like this.

I've registered runner with tag "testing"
created tag "testing" in gitlab
binded this runner, with  particular project
I've also added the same tag e.g. "testing"in my local repo.

BUT how exactly is running my jobs dependent on those tags? Are all these operations necessary? If I push new code to repo, *.yml file is executed anyway as far as I tested.
So what if I want to run build only when I define a version in a commit?
IDK...
   git commit --tags "v. 2.0" -m "this is version 2.0" (probably not right)

But of course it should be universal, so I don't have to always tell, which tag to use to trigger the runner, but for example let him recognize numeric values.
As you can see, I'm fairly confused... If you could elaborate how exactly tags work, so I would be able to understand the concept, I would be really grateful.

[Assistant]
Tags for GitLab CI and tags for Git are two different concepts.
When you write your .gitlab-ci.yml, you can specify some jobs with the tag testing.  If a runner with this tag associated is available, it will pickup the job.
In Git, within your repository, tags are used to mark a specific commit.  It is often used to tag a version.
The two concepts can be mixed up when you use tags (in Git) to start your pipeline in GitLab CI.  In your .gitlab-ci.yml, you can specify the section only with tags.
Refer to GitLab documentation for tags and only.
An example is when you push a tag with git:
$ git tag -a 1.0.0 -m "1.0.0"
$ git push origin 1.0.0

And a job in .gitlab-ci.yml like this:
compile:
    stage: build
    only: [tags]
    script:
        - echo Working...
    tags: [testing]

would start using a runner with the testing tag.
By my understanding, what is missing in your steps is to specify the tag testing to your runner.  To do this, go in GitLab into your project.  Next to
Wiki, click on Settings.  Go to CI/CD Pipelines and there you have your runner(s).  Next to its Guid, click on the pen icon.  On next page the tags can be modified.


[System] You are a helpful assistant.

[User] git-grep - Print lines matching a pattern  --color[=<when>]

[Assistant]
Show colored matches.
The value must be always (the default), never, or auto.


[System] You are a helpful assistant.

[User]
fetch from origin with deleted remote branches?
When I do git fetch origin and origin has a deleted branch, it doesn't seem to update it in my repository. When I do git branch -r it still shows origin/DELETED_BRANCH.
How can I fix this?

[Assistant]
You need to do the following
git fetch -p

The -p or --prune argument will update the local database of remote branches.


[System] You are a helpful assistant.

[User] git-grep - Print lines matching a pattern  --recurse-submodules

[Assistant]
Recursively search in each submodule that is active and
checked out in the repository.  When used in combination with the <tree> option the prefix of all submodule output will be the name of
the parent project’s <tree> object.  This option cannot be used together
with --untracked , and it has no effect if --no-index is specified.


[System] You are a helpful assistant.

[User]
Migrate or export Github wiki to Gitlab

Currently we are working with github and we are actually quiet happy with it. But the costs will grow more and more in near future. Now we've started evaluating other git solutions and stumbled over gitlab, and i've to say, it looks very interesting for us. I've seen that there is as well a wiki feature similar to github. But one important thing is nowhere described...
The only thing i've found is this two year old entry https://groups.google.com/forum/#!msg/gitlabhq/YSM_Il9yk04/_-ybpN4BekYJ
Does anybody know if there are any news in that matter? it looks like it is possible, but how? is there any manual or howto that could help me?
Thanks a lot!

[Assistant]
Github wikis and GitLab wikis are both just Git repositories containing text files, so you can just pull from one and push to the other.
Go to any page on your Github wiki and click the Clone URL button. You'll get a URL like https://github.com/Homebrew/homebrew.wiki.git. Clone it to your computer:
git clone https://github.com/Homebrew/homebrew.wiki.git
cd homebrew.wiki

Then, on your GitLab wiki, click the Git Access tab, find the URL in the instructions (in the first line under the Clone Your Wiki heading), and push to that URL:
git push https://gitlab.com/adambrenecki/test-project.wiki.git

If you can't find the URLs, they should be roughly the same as on this page, with the usernames/repo names changed as appropriate.


[System] You are a helpful assistant.

[User] git-notes - Add or inspect object notes  --stdin

[Assistant]
Also read the object names to remove notes from the standard
input (there is no reason you cannot combine this with object
names from the command line).


[System] You are a helpful assistant.

[User] git-checkout-index - Copy files from the index to the working tree  Export files with a prefix

[Assistant] $ git checkout-index --prefix=.merged- Makefile This will check out the currently cached copy of Makefile into the file .merged-Makefile .


[System] You are a helpful assistant.

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

[Assistant] raw body (unwrapped subject and body)


[System] You are a helpful assistant.

[User]
How to store a git config as part of the repository?
I'm using filters to mangle files during checkout like described here.
Now the problem is that filter definition is only stored in my local configuration file:
$ cat .git/config
....
[filter "dater"]
        smudge = /home/.../expand_date
        clean = perl -pe \"s/\\\\\\$Date[^\\\\\\$]*\\\\\\$/\\\\\\$Date\\\\\\$/\"

If my coworkers want to benefit from this Date expansion, they need to copy my filter definition. And if I change it, I need to notify them, etc..
So can I store this filter definition part of .git/config in repository and make git use it?

[Assistant]
There are 3 supported scopes of .gitconfig file: --system, --global, --local. You can also create a custom configuration file, and include it in one of the supported files.
For your needs custom - is the right choice. Instead of writing your filter in .git/config you should save it in .gitconfig file in your repository root:
your-repo/
│
├── .git/
│   ├── config
│
├── .gitconfig
│

Create the .gitconfig with your filter and commit the changes. Then your colleagues will always keep it updated -- but they will have to include it manually. It is not possible to automatically include your custom configuration file through git alone, because it creates a security vulnerability.
To apply this configuration for a single repository, each user will need to run the following command in your-repo/:
git config --local include.path ../.gitconfig

Reference: https://git-scm.com/docs/git-config#_includes
Be careful not to store personal data in the custom .gitconfig, like user.*, keep those in your global .gitconfig.


[System] You are a helpful assistant.

[User]
Fast-forward merge is not possible. To merge this request, first rebase locally
Recently, I have created newbranch and created a merge request to Master branch. Before TeamLead accept merge request into Master branch another team member was committed another fix to the same branch(newbranch). After that I committed my local changes and pulled the changes in newbranch to local branch. And I pushed my local commit to newbranch

My TeamLead told me to rebase my branch to an earlier version.
And resolve conflicts.
I don't know what to do now. Any idea?

[Assistant]
Starting on your newBranch:
git checkout master to get back on the master branch
git pull origin master to get the most up-to-date version of the master branch
git checkout newBranch to get back on your newBranch
git rebase origin/master -i to perform an interactive rebase. The command will take you through and let you pick commits, rename them, squash them, etc. Assuming you will want to keep them all, it will pause when there are merge conflicts and then you'll have to resolve them in your text editor, it will tell you where (in your text editor) that the conflicts occur. You will have to add those files after fixing them then do git rebase --continue to proceed with the rebase.
When you're done with the rebase your newBranch will be synced up with master and have any commits in master that weren't there when you started your work, and all merge conflicts will be resolved so that you can easily merge your newBranch.


[System] You are a helpful assistant.

[User]
How to delete a Gitlab repository

I have googled a while now and could not find a solution that fits the current UI of Gitlab. I am trying to remove a repository I previously created on Gitlab. I navigate to edit project by clicking the settings cog on the right. After scrolling down to the bottom I can not find a section called remove project. Instead, I only see rename project. I should have the proper rights because I am the master of the project.
Any ideas?

[Assistant] Go to Settings > Expand Advanced Settings > Remove Project


[System] You are a helpful assistant.

[User]
Creating folders inside a GitHub repository without using Git
I want to add a new folder to my newly created GitHub repository without installing the Git setup for (Mac, Linux, and Windows). Is it possible to do so?
I can't have Git all the time with me when I work on different systems/machines. I know how to add files directly in a repository on github.com/[USER]/[REPO]. Can we create a folder as well?

[Assistant]
After searching a lot I find out that it is possible to create a new folder from the web interface, but it would require you to have at least one file within the folder when creating it.
When using the normal way of creating new files through the web interface, you can type in the folder into the file name to create the file within that new directory.
For example, if I would like to create the file filename.md in a series of sub-folders, I can do this (taken from the GitHub blog):


[System] You are a helpful assistant.

[User]
Git hook to send email notification on repo changes
How do I configure the appropriate Git hook to send a summary email whenever a set of changes is pushed to the upstream repository?

[Assistant]
Another, more modern way to do this is with git-multimail, as suggested by Chords below.

This is how you did it in 2009.
You could add something like this to your post-receive hook in $GITDIR/hooks, or use the script in the contrib directory of the source (Available here)


[System] You are a helpful assistant.

[User]
Variable inside variable gitlab ci

Is there a way to use predefined variable inside custom variable in gitlab ci like this:
before_script:
  - cat "${$CI_COMMIT_REF_NAME}" >> .env

to extract the name of branch from $CI_COMMIT_REF_NAME and use it as a name of custom variable
Update:

[Assistant]
Check out GitLab 14.3 (September 2021)

Use variables in other variables
CI/CD pipeline execution scenarios can depend on expanding variables declared in a pipeline or using GitLab predefined variables within another variable declaration.
In 14.3, we are enabling the “variables inside other variables” feature on GitLab SaaS.
Now you can define a variable and use it in another variable definition within the same pipeline.
You can also use GitLab predefined variables inside of another variable declaration.
This feature simplifies your pipeline definition and eliminates pipeline management issues caused by the duplicating of variable data.
Note - for GitLab self-managed users the feature is disabled by default.
To use this feature, your GitLab administrator will need to enable the feature flag.
(demo -- video)

See [Documentation]https://gitlab.com/gitlab-org/gitlab/-/blob/ee8cb300efb6f917eab6d865c9d430eb62077b44/doc/ci/variables/index.md#use-variables-in-other-variables) and Issue.

Q4 2023: the documentation now refers to Use CI/CD variables in other variables

Use CI/CD variables in other variables
You can use variables inside other variables:
job:
 variables:
   FLAGS: '-al'
   LS_CMD: 'ls "$FLAGS"'
 script:
   - 'eval "$LS_CMD"'  # Executes 'ls -al'

Use the $ character in CI/CD variables.
If you do not want the $ character interpreted as the start of another variable, use $$ instead:
job:
 variables:
   FLAGS: '-al'
   LS_CMD: 'ls "$FLAGS" $$TMP_DIR'
 script:
   - 'eval "$LS_CMD"'  # Executes 'ls -al $TMP_DIR'

Prevent CI/CD variable expansion
Introduced in GitLab 15.7.
Expanded variables treat values with the $ character as a reference to another variable.
CI/CD variables are expanded by default. To treat variables with a $ character as raw strings, disable variable expansion for the variable

dba asks in the comments:

Does this include or exclude using globally defined variables?

dba's own answer:

Global variables can be reused, but they need the local_var: ${global_var} syntax with recursive expansion (independent of the shell).


[System] You are a helpful assistant.

[User]
Can I checkout github wikis like a git repository?

I want to modify and view github wikis with local editor like Emacs, and Google Code wikis can be checked out just like code. Is there any way to checkout github wikis? Or is there any other git repository provider offers such feature?

[Assistant]
You can now!
git clone https://github.com/user/project.wiki.git

or if you use ssh
git clone [email protected]:username/project.wiki.git


[System] You are a helpful assistant.

[User]
Git error on commit after merge - fatal: cannot do a partial commit during a merge
I ran a git pull that ended in a conflict. I resolved the conflict  and everything is fine now (I used mergetool also).
When I commit the resolved file with git commit file.php -m "message" I get the error:
fatal: cannot do a partial commit during a merge.

I had the same issue before and using -a in commit worked perfectly. I think it's not the perfect way because I don't want to commit all changes. I want to commit files separately with separate comments. How can I do that? Why doesn't git allow users to commit files separately after a merge? I could not find a satisfactory answer to this problem.

[Assistant]
I found that adding "-i" to the commit command fixes this problem for me. The -i basically tells it to stage additional files before committing.
That is:
git commit -i myfile.php


[System] You are a helpful assistant.

[User] git-for-each-ref - Output information on each ref  contents:signature

[Assistant] The optional GPG signature of the tag.


[System] You are a helpful assistant.

[User]
Git and Team Foundation Server
Update: I don't use TFS anymore. But from the comments I can see that git-tfs is obviously the way to go nowadays.
Has anybody experience using Git as an offline solution for Team Foundation Server?
For Subversion you could use git-svn to keep a private repository with a svn backend.
I tried to use SvnBridge and git-svn to work with TFS. At first it looked promising but Visual Studio recognizes the solution as being under TFS version control and interferes during commit.
Are there other ways to combine those two?

[Assistant]
I've started working on a tool called git-tfs, similar in some ways to git-svn.
https://github.com/git-tfs/git-tfs


[System] You are a helpful assistant.

[User]
Remote origin already exists on 'git push' to a new repository

I have my project on GitHub at some location, [email protected]:myname/oldrep.git.
Now I want to push all my code to a new repository at some other location, [email protected]:newname/newrep.git.
I used the command:
git remote add origin [email protected]:myname/oldrep.git

but I am receiving this:

fatal: remote origin already exists.

[Assistant]
You are getting this error because "origin" is not available. "origin" is a convention not part of the command. "origin" is the local name of the remote repository.
For example you could also write:
git remote add myorigin [email protected]:myname/oldrep.git
git remote add testtest [email protected]:myname/oldrep.git

See the manual:
http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
To remove a remote repository you enter:
git remote rm origin

Again "origin" is the name of the remote repository if you want to
remove the "upstream" remote:
git remote rm upstream


[System] You are a helpful assistant.

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

[Assistant] Remove unnecessary whitespace


[System] You are a helpful assistant.

[User]
Github - unexpected disconnect while reading sideband packet

I've got quite interesting problem.
I tried to send some projects via bash to repo and recently there was a problem with sending it.
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 16 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (25/25), 187.79 KiB | 9.39 MiB/s, done.
Total 25 (delta 1), reused 0 (delta 0), pack-reused 0
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly

The funny part is that 10 min earlier I can send it without any problems.
I tried with getting new repo, creating new file, reinstalling git, git config --global http.postBuffer 524288000 with bigger numbers as well, also https.postBuffer and so on. Also install desktop version the same issue come in.
I've got problems mostly with React apps.
Anyone know the solution ? What could go wrong ?

[Assistant]
First of all, check your network connection stability.
If there is no problem with network connection try another solution; it may work:
On Linux
Execute the following in the command line before executing the Git command:
export GIT_TRACE_PACKET=1
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1

On Windows
Execute the following in the command line before executing the Git command:
set GIT_TRACE_PACKET=1
set GIT_TRACE=1
set GIT_CURL_VERBOSE=1

In addition:
git config --global core.compression 0
git clone --depth 1 <repo_URI>
# cd to your newly created directory
git fetch --unshallow
git pull --all

For PowerShell users:
As kodybrown said in comments:
$env:GIT_TRACE_PACKET=1
$env:GIT_TRACE=1
$env:GIT_CURL_VERBOSE=1


[System] You are a helpful assistant.

[User] git-for-each-ref - Output information on each ref  <pattern>…

[Assistant]
If one or more patterns are given, only refs are shown that
match against at least one pattern, either using fnmatch(3) or
literally, in the latter case matching completely or from the
beginning up to a slash.


[System] You are a helpful assistant.

[User]
Git: Pull from other remote

I have created a fork from a project on GitHub.
How can I now pull changes from the project that I forked from?

[Assistant]
git pull is really just a shorthand for git pull <remote> <branchname>, in most cases it's equivalent to git pull origin master. You will need to add another remote and pull explicitly from it. This page describes it in detail:
http://help.github.com/forking/


[System] You are a helpful assistant.

[User]
Make the current commit the only (initial) commit in a Git repository?
I  currently have a local Git repository, which I push to a Github repository.
The local repository has ~10 commits, and the Github repository is a synchronised duplicate of this.
What I'd like to do is remove ALL the version history from the local Git repository, so the current contents of the repository appear as the only commit (and therefore older versions of files within the repository are not stored).
I'd then like to push these changes to Github.
I have investigated Git rebase, but this appears to be more suited to removing specific versions.
Another potential solution is to delete the local repo, and create a new one - though this would probably create a lot of work!
ETA: There are specific directories / files that are untracked - if possible I would like to maintain the untracking of these files.

[Assistant]
Here's the brute-force approach. It also removes the configuration of the repository.
Note: This does NOT work if the repository has submodules! If you are using submodules, you should use e.g. interactive rebase
Step 1: remove all history (Make sure you have a backup, this cannot be reverted)
cat .git/config  # save your <github-uri> somewhere
rm -rf .git

Step 2: reconstruct the Git repo with only the current content
Before step 2 if you have not set up init.defaultBranch configuration then, please do it via git config --global init.defaultBranch <branch-name> you may choose main as <branch-name> in the current example
git init
git add .
git commit -m "Initial commit"

Step 3: push to GitHub.
git remote add origin <github-uri>
git push -u --force origin main


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  log.graphColors

[Assistant]
A list of colors, separated by commas, that can be used to draw
history lines in git log --graph .


[System] You are a helpful assistant.

[User]
Run git commands from a C# function
How can my C# code run git commands when it detects changes in tracked file? I am writing a VisualStudio/C# console project for this purpose.
I am new to the the .NET environment and currently working on integrating automated GIT commits to a folder. I need to automatically commit any change/add/delete on a known folder and push that to a git remote. Any guidance appreciated. Thank you.
Here is what I have and the last one is the one I need some guidance with:

Git repository initially set up on folder with proper ignore file (done).
I am using C# FileSystemWatcher to catch any changes on said folder (done).
Once my project detects a change it needs to commit and push those changes (pending).

Tentative commands the project needs to run:
git add -A
git commit "explanations_of_changes"
git push our_remote

NOTE: This code (with no user interaction) will be the only entity committing to this repo so I am not worried about conflicts and believe this flow will work.

[Assistant]
I realize this is an old question but I wanted to add the solution I recently came across to help those in the future.
The PowerShell class provides an easy way to interact with git. This is part of the System.Management.Automation namespace in .NET. Note that System.Management.Automation.dll is available via NuGet.
string directory = ""; // directory of the git repository

using (PowerShell powershell = PowerShell.Create()) {
    // this changes from the user folder that PowerShell starts up with to your git repository
    powershell.AddScript($"cd {directory}");

    powershell.AddScript(@"git init");
    powershell.AddScript(@"git add *");
    powershell.AddScript(@"git commit -m 'git commit from PowerShell in C#'");
    powershell.AddScript(@"git push");

    Collection<PSObject> results = powershell.Invoke();
}

In my opinion this is cleaner and nicer than using the Process.Start() approach. You can modify this to your specfic needs by editing the scripts that are added to the powershell object.
As commented by @ArtemIllarionov, powershell.Invoke() does not return errors but the Streams property has output information. Specifically powerShell.Streams.Error for errors.


[System] You are a helpful assistant.

[User]
Can you issue pull requests from the command line on GitHub?
It seems like you have to interact with github.com to initiate a pull request. Is this so?

[Assistant]
UPDATE: The hub command is now an official github project and also supports creating pull requests
ORIGINAL:
Seems like a particularly useful thing to add to the hub command: http://github.com/defunkt/hub or the github gem: http://github.com/defunkt/github-gem
I suggest filing an issue with those projects asking for it. The github guys are pretty responsive.


[System] You are a helpful assistant.

[User] git-svn - Bidirectional operation between a Subversion repository and Git  -l<num>  --find-copies-harder

[Assistant]
Only used with the dcommit , set-tree and commit-diff commands. They are both passed directly to git diff-tree ; see git-diff-tree for more information. config key: svn.l
config key: svn.findcopiesharder


[System] You are a helpful assistant.

[User] git - the stupid content tracker  -c <name>=<value>

[Assistant]
Pass a configuration parameter to the command. The value
given will override values from configuration files.
The <name> is expected in the same format as listed by git config (subkeys separated by dots). Note that omitting the = in git -c foo.bar ... is allowed and sets foo.bar to the boolean true value (just like [foo]bar would in a
config file). Including the equals but with an empty value (like git -c
foo.bar= ... ) sets foo.bar to the empty string which git config
--type=bool will convert to false .


[System] You are a helpful assistant.

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

[Assistant] The stage of the file which is recorded in the index.


[System] You are a helpful assistant.

[User] git-gc - Cleanup unnecessary files and optimize the local repository  gc.reflogExpire  gc.<pattern>.reflogExpire

[Assistant]
git reflog expire removes reflog entries older than
this time; defaults to 90 days. The value "now" expires all
entries immediately, and "never" suppresses expiration
altogether. With "<pattern>" (e.g.
"refs/stash") in the middle the setting applies only to
the refs that match the <pattern>.


[System] You are a helpful assistant.

[User]
Add newly created specific folder to .gitignore in Git
I had a clean working directory and brought in a clone from a Git repo last night.
But now my local server created and contains a stats folder which I want to ignore.
I can't seem to get Git to ignore this folder when I run a git status.
On branch master
Your branch is ahead of 'origin/master' by 1 commit.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file: app_public/views/pages/privacy.php
    new file: app_public/views/pages/terms.php
    new file: public_html/stats/ctry_usage_200908.png
    new file: public_html/stats/daily_usage_200908.png
    new file: public_html/stats/dns_cache.db
    new file: public_html/stats/hourly_usage_200908.png
    new file: public_html/stats/index.html
    new file: public_html/stats/usage.png
    new file: public_html/stats/usage_200908.html
    new file: public_html/stats/webalizer.current
    new file: public_html/stats/webalizer.hist

Changed but not updated:
    modified: .gitignore

I added in my .gitignore a few different lines but it still trying to add them:
public_html/stats
public_html/stats/**
public_html/stats/**/*
public_html/stats/*

[Assistant]
For this there are two cases
Case 1: File already added to git repo.
Case 2: File newly created and its status still showing as untracked file when using
git status

If you have case 1:
STEP 1:
Then run
git rm --cached filename

to remove it from git repo cache
if it is a directory then  use
git rm -r --cached  directory_name

STEP 2: If Case 1 is over then create new file named .gitignore in your git repo
STEP 3: Use following to tell git to ignore / assume file is unchanged
git update-index --assume-unchanged path/to/file.txt

STEP 4: Now, check status using git status open .gitignore in your editor nano, vim, geany etc... any one, add the path of the file / folder to ignore. If it is a folder then user folder_name/* to ignore all file.
If you still do not understand read the article git ignore file link.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  -s  --no-patch

[Assistant]
Suppress all output from the diff machinery.  Useful for
commands like git show that show the patch by default to
squelch their output, or to cancel the effect of options like --patch , --stat earlier on the command line in an alias.


[System] You are a helpful assistant.

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

[Assistant] Perform merge without touching index or working tree


[System] You are a helpful assistant.

[User] git-restore - Restore working tree files  -s <tree>  --source=<tree>

[Assistant]
Restore the working tree files with the content from the given
tree. It is common to specify the source tree by naming a
commit, branch or tag associated with it. If not specified, the contents are restored from HEAD if --staged is
given, otherwise from the index. 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 unreferenced blobs from my Git repository
I have a GitHub repository that had two branches - master and release.
The release branch contained binary distribution files that were contributing to a very large repository size (more than 250 MB), so I decided to clean things up.
First I deleted the remote release branch, via git push origin :release.
Then I deleted the local release branch. First I tried git branch -d release, but Git said "error: The branch 'release' is not an ancestor of your current HEAD." which is true, so then I did git branch -D release to force it to be deleted.
But my repository size, both locally and on GitHub, was still huge. So then I ran through the usual list of Git commands, like git gc --prune=today --aggressive, without any luck.
By following Charles Bailey's instructions at SO 1029969 I was able to get a list of SHA-1 hashes for the biggest blobs. I then used the script from SO 460331 to find the blobs...and the five biggest don't exist, though smaller blobs are found, so I know the script is working.
I think these blogs are the binaries from the release branch, and they somehow got left around after the delete of that branch. What's the right way to get rid of them?

[Assistant]
I present to you this useful command, "git-gc-all", guaranteed to remove all your Git garbage until they might come up extra configuration variables:
git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 \
    -c gc.rerereunresolved=0 -c gc.pruneExpire=now gc

You might also need to run something like these first:
git remote rm origin
rm -rf .git/refs/original/ .git/refs/remotes/ .git/*_HEAD .git/logs/
git for-each-ref --format="%(refname)" refs/original/ |
    xargs -n1 --no-run-if-empty git update-ref -d

You might also need to remove some tags:
git tag | xargs git tag -d


[System] You are a helpful assistant.

[User] git - the stupid content tracker  GIT_SSL_NO_VERIFY

[Assistant]
Setting and exporting this environment variable to any value
tells Git not to verify the SSL certificate when fetching or
pushing over HTTPS.


[System] You are a helpful assistant.

[User]
Can't publish private npm package on Gitlab - E404 Not found PUT

I've tried many different docs and tutorials to publish a scoped npm package on a private gitlab instance.
So far I've:
Created a deploy token with package write & read permissions:

Setup a .npmrc file with the following contents:
@<scope>:registry=https://<domain>/api/v4/packages/npm/

//<domain>/api/v4/projects/<id>/packages/npm/:_authToken=<token>

//<domain>/api/v4/packages/npm/:_authToken=<token>

Added "publishConfig" to "package.json":
{
  "name": "@<scope>/<name>",
  "version": "1.0.0",
  "main": "dist/index.js",
  "license": "MIT",
  "publishConfig": {
    "@<scope>:registry": "https://<domain>/api/v4/projects/<id>/packages/npm"
  },
  "scripts": {
    "build": "tsc",
    "prepublish": "tsc"
  },
  "devDependencies": {
    "ts-node": "^9.1.1"
  }
}

Verified that the repo allows packages to be stored:

But everytime I try and run either npm publish or yarn publish, it builds, packages but fails to publish:

The log file verbosily repeats the error log above.
I'm trying to release a private SDK for an internal service and would need a way to publish it so only those with the correct credentials can install it on their projects.
The link provided (Not Found - PUT https:// <link...> ) redirects to npmjs.com, which I believe wasn't supposed to happen, since I'm trying to store it on Gitlab instead of purchasing an organization on npmjs.
I've tried this process both on the private domain (running gitlab 13.9.1) and on https://gitlab.com, both with the same result on the same repository configuration disclosed above.
Am I missing some step? Thanks in advance!

[Assistant]
Your .npmrc file has both instance and project level endpoints, but if you're using a project deploy token, the authentication of the token you're providing is scoped to the project, so you should only have the project endpoint.
@<scope>:registry=https://<domain>/api/v4/projects/<ID>/packages/npm/

//<domain>/api/v4/projects/<ID>/packages/npm/:_authToken=<TOKEN>


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-write-tree

[Assistant] Create a tree object from the current index


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  core.pager

[Assistant]
Text viewer for use by Git commands (e.g., less ).  The value
is meant to be interpreted by the shell.  The order of preference
is the $GIT_PAGER environment variable, then core.pager configuration, then $PAGER , and then the default chosen at
compile time (usually less ). When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at
all).  If you want to selectively override Git’s default setting
for LESS , you can set core.pager to e.g. less -S .  This will
be passed to the shell by Git, which will translate the final
command to LESS=FRX less -S . The environment does not set the S option but the command line does, instructing less to truncate
long lines. Similarly, setting core.pager to less -+F will
deactivate the F option specified by the environment from the
command-line, deactivating the "quit if one screen" behavior of less .  One can specifically activate some flags for particular
commands: for example, setting pager.blame to less -S enables
line truncation only for git blame . Likewise, when the LV environment variable is unset, Git sets it
to -c .  You can override this setting by exporting LV with
another value or setting core.pager to lv +c .


[System] You are a helpful assistant.

[User]
How to fetch entire repository with GitLab CI/CD?

I'm currently setting up GitLab CI/CD. We use GitVersion in our project, which throws the following error:
/root/.nuget/packages/gitversiontask/5.3.7/build/GitVersionTask.targets(46,9): error : InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
According to this blog this happens, when the CI-server does not fetch the full repository (we have both a develop and a master branch, but I'm working on a different one). For Jenkins we solved this problem by expanding the checkout stage:
stage("Checkout") { gitlabCommitStatus(name: "Checkout") {

    // These are the normal checkout instructions
    cleanWs()
    checkout scm

    // This is the additional checkout to get all branches
    checkout([
      $class: 'GitSCM',
      branches: [[name: 'refs/heads/'+env.BRANCH_NAME]],
      extensions: [[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: '']],
      userRemoteConfigs: scm.userRemoteConfigs,
    ])

    sh "git checkout ${env.BRANCH_NAME}"
    sh "git reset --hard origin/${env.BRANCH_NAME}"
}}

I'm essentially looking for something equivalent to this for the .gitlab-ci.yml file.

[Assistant]
By default, runners download your code with a 'fetch' rather than a 'clone' for speed's sake, but it can be configured a number of ways. If you want all jobs in your project's pipeline to be cloned rather than fetched, you can change the default in your CI Settings:

If you don't want all your jobs to clone since it's slower, you can change it in your .gitlab-ci.yml for your job:
my_job:
  stage: deploy
  variables:
    GIT_STRATEGY: clone
  script:
    - ./deploy

You can read more about the GIT_STRATEGY variable here: https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-strategy
Note: You can also set this variable to none, which is useful if you don't need the code but maybe an artifact created by a previous job. Using this, it won't checkout any code, but skip straight to your script.


[System] You are a helpful assistant.

[User]
Why can't I push this up-to-date Git subtree?
I am using Git subtree with a couple of projects that I am working on, in order to share some base code between them. The base code gets updated often, and the upgrades can happen in anyone of the projects, with all of them getting updated, eventually.
I have ran into a problem where git reports that my subtree is up to date, but pushing gets rejected. For example:
#! git subtree pull --prefix=public/shared project-shared master
From github.com:****
* branch            master     -> FETCH_HEAD
Already up-to-date.

If I push, I should get a message that there is nothing to push... Right? RIGHT? :(
#! git subtree push --prefix=public/shared project-shared master
git push using:  project-shared master
To [email protected]:***
! [rejected]        72a6157733c4e0bf22f72b443e4ad3be0bc555ce -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:***'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

What could be the reason for this? Why is pushing failing?

[Assistant]
I found the answer on this blog comment https://coderwall.com/p/ssxp5q

If you come across the "Updates were rejected because the tip of your current branch is
  behind. Merge the remote changes (e.g. 'git pull')" problem when you're pushing (due to
  whatever reason, esp screwing about with git history) then you'll need to nest git
  commands so that you can force a push to heroku. e.g, given the above example:

git push heroku `git subtree split --prefix pythonapp master`:master --force


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  column.ui

[Assistant]
Specify whether supported commands should output in columns.
This variable consists of a list of tokens separated by spaces
or commas: These options control when the feature should be enabled
(defaults to never ): always always show in columns never never show in columns auto show in columns if the output is to the terminal These options control layout (defaults to column ).  Setting any
of these implies always if none of always , never , or auto are
specified. column fill columns before rows row fill rows before columns plain show in one column Finally, these options can be combined with a layout option (defaults
to nodense ): dense make unequal size columns to utilize more space nodense make equal size columns


[System] You are a helpful assistant.

[User] git-log - Show commit logs  <paths>

[Assistant] Commits modifying the given <paths> are selected.


[System] You are a helpful assistant.

[User]
Git: cancel an interactive rebase
I like to git rebase -i HEAD~5 to squash my commits down. Sometimes I think I need to go back 5 commits but then realize I need 7. However git has already brought up the rebase editor .git/rebase-merge/git-rebase-todo in vim.
If I quit that buffer (vim) then git says:
Successfully rebased and updated refs/heads/my-branchname

Is there a way to stop the rebase from w/in the editor? I suppose I could git rebase --abort from another shell but not sure what that would do to the git-rebase-todo file that I'd be in the middle of editing in another buffer.

[Assistant]
You can make vim exit with a non-zero exit code to cancel the rebase by typing :cq. The result of this is:
$ git rebase -i HEAD~4
# enter vim, then type :cq<enter>
Could not execute editor

From the vim help page we see that cq is short for cquit:
                                                        *:cq* *:cquit*
:cq[uit][!]             Quit Vim with an error code, so that the compiler
                        will not compile the same file again.
                        WARNING: All changes in files are lost!  Also when the
                        [!] is not used.  It works like ":qall!" |:qall|,
                        except that Vim returns a non-zero exit code.


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  diff.<driver>.cachetextconv

[Assistant]
Set this option to true to make the diff driver cache the text
conversion outputs.  See gitattributes for details. araxis bc codecompare deltawalker diffmerge diffuse ecmerge emerge examdiff guiffy gvimdiff kdiff3 kompare meld nvimdiff opendiff p4merge smerge tkdiff vimdiff winmerge xxdiff


[System] You are a helpful assistant.

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

[Assistant] show the trust level for the key used to sign a signed commit


[System] You are a helpful assistant.

[User] git-cat-file - Provide contents or details of repository objects  <object>

[Assistant]
The name of the object to show.
For a more complete list of ways to spell object names, see
the "SPECIFYING REVISIONS" section in gitrevisions .


[System] You are a helpful assistant.

[User]
Pull latest changes for all git submodules
We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest version of every dependent submodule.
How do I pull the latest changes for all git submodules?

[Assistant]
If it's the first time you check-out a repo you need to use --init first:
git submodule update --init --recursive

For git 1.8.2 or above, the option --remote was added to support updating to latest tips of remote branches:
git submodule update --recursive --remote

This has the added benefit of respecting any "non default" branches specified in the .gitmodules or .git/config files (if you happen to have any, default is origin/master, in which case some of the other answers here would work as well).
For git 1.7.3 or above you can use (but the below gotchas around what update does still apply):
git submodule update --recursive

or:
git pull --recurse-submodules

if you want to pull your submodules to latest commits instead of the current commit the repo points to.
See git-submodule(1) for details


[System] You are a helpful assistant.

[User]
Local git config not overriding global user for project
I have a global git user configured, but want to use a different user for a single git project.
Within that project, I've used git config --local user.name "localuser" and git config --local user.email "[email protected]" to set the local project's user and email.
However, when I try to push to my remote on github, I get this error:
remote: Permission to localuser/repo.git denied to globaluser.
fatal: unable to access 'https://github.com/localuser/repo.git/': The requested URL returned error: 403

Here's some output that might help with diagnosis:
git remote -v:
github  https://github.com/localuser/repo.git (fetch)
github  https://github.com/localuser/repo.git (push)

git config --list:
user.name=globaluser
[email protected]
...

git config --local --list:
user.name=localuser
[email protected]
...

git config user.name:
localuser

[Assistant]
I had committed my changes and received a permission denied with my global user. Subsequently setting the local user did nothing, though git config user.name reported the correct local user.
What worked was (courtesy of this google groups thread):
git commit --amend --reset-author
I presume the committed changes had the original author attached.


[System] You are a helpful assistant.

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

[Assistant] SYNOPSIS git submodule [--quiet] [--cached] git submodule [--quiet] add [<options>] [--] <repository> [<path>] git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…] git submodule [--quiet] init [--] [<path>…] git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>…) git submodule [--quiet] update [<options>] [--] [<path>…] git submodule [--quiet] set-branch [<options>] [--] <path> git submodule [--quiet] set-url [--] <path> <newurl> git submodule [--quiet] summary [<options>] [--] [<path>…] git submodule [--quiet] foreach [--recursive] <command> git submodule [--quiet] sync [--recursive] [--] [<path>…] git submodule [--quiet] absorbgitdirs [--] [<path>…]


[System] You are a helpful assistant.

[User] git-branch - List, create, or delete branches  Delete an unneeded branch

[Assistant]
$ git clone git://git.kernel.org/.../git.git my.git
$ cd my.git
$ git branch -d -r origin/todo origin/html origin/man (1) $ git branch -D test (2) Delete the remote-tracking branches "todo", "html" and "man". The next fetch or pull will create them again unless you configure them not to.
See git-fetch . Delete the "test" branch even if the "master" branch (or whichever branch
is currently checked out) does not have all commits from the test branch.


[System] You are a helpful assistant.

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

[Assistant]
Include a line “log size <number>” in the output for each commit,
where <number> is the length of that commit’s message in bytes.
Intended to speed up tools that read log messages from git log output by allowing them to allocate space in advance.


[System] You are a helpful assistant.

[User]
How to see the file size history of a single file in a git repository?
Is there anyway to see how a file's size has changed through time in a git repository? I want to see how my main.js file (which is the combination of several files and minified) has grown and shrunk over time.

[Assistant]
You can use either git ls-tree -r -l <revision> <path> to get the blob size at given revision, e.g.

$ git ls-tree -r -l v1.6.0 gitweb/README
100644 blob 825162a0b6dce8c354de67a30abfbad94d29fdde   16067    gitweb/README

From the docs:
 -r                    recurse into subtrees
 -l, --long            include object size

The blob size in this example is '16067'.  The disadvantage of this solution is that git ls-tree can process only one revision at once.
You can use instead git cat-file --batch-check < <list-of-objects> instead, feeding it blob identifiers.  If location of file didn't change through history (file was not moved), you can use git rev-list <starting-point> -- <path> to get list of revisions touching given path, translate them into names of blobs using <revision>:<path> extended SHA-1 syntax (see git-rev-parse manpage), and feed it to git cat-file.  Example:

$ git rev-list -5 v1.6.0 -- gitweb/README |
  sed -e 's/$/:gitweb\/README/g' |
  git cat-file --batch-check
825162a0b6dce8c354de67a30abfbad94d29fdde blob 16067
6908036402ffe56c8b0cdcebdfb3dfacf84fb6f1 blob 16011
356ab7b327eb0df99c0773d68375e155dbcea0be blob 14248
8f7ea367bae72ea3ce25b10b968554f9b842fffe blob 13853
8dfe335f73c223fa0da8cd21db6227283adb95ba blob 13801


[System] You are a helpful assistant.

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

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


[System] You are a helpful assistant.

[User]
How do I exclude files from git ls-files?
How do I list everything except markdown files? I have tried to run ls-files with the --exclude flag, but the excluded files are still shown in the output.
My git version is 2.6.4 (Apple Git-63)
$ git ls-files
ChromeExt/read-coffee
Node/README.md
Node/web-scraping
README.md

$ git ls-files --exclude *.md
ChromeExt/read-coffee
Node/README.md
Node/web-scraping
README.md

[Assistant]
Git has its own way to extend glob patterns, and that includes a way to exclude files that match one pattern but not another. For example, the following will list all paths not ending in .md:
git ls-files -- . ':!:*.md'

It's important to quote the pattern, because you want git to parse it, not the shell.
And to match all files ending with .js, except the ones ending with .min.js:
git ls-files -- '*.js' ':!:*.min.js'

You can also use this with other commands, such as git grep:
git grep -w funcname -- '*.js' ':!:*.min.js'

This syntax is explained under pathspec in gitglossary (or git help glossary or man gitglossary)


[System] You are a helpful assistant.

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

[Assistant]
This expands to the object name of the delta base for the
given object, if it is stored as a delta.  Otherwise it
expands to the null object name (all zeroes).


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --output=<file>

[Assistant] Output to a specific file instead of stdout.


[System] You are a helpful assistant.

[User] git-rev-parse - Pick out and massage parameters  <rev>^{<type>} , e.g. v0.99.8^{commit}

[Assistant]
A suffix ^ followed by an object type name enclosed in
brace pair means dereference the object at <rev> recursively until
an object of type <type> is found or the object cannot be
dereferenced anymore (in which case, barf).
For example, if <rev> is a commit-ish, <rev>^{commit} describes the corresponding commit object.
Similarly, if <rev> is a tree-ish, <rev>^{tree} describes the corresponding tree object. <rev>^0 is a short-hand for <rev>^{commit} . <rev>^{object} can be used to make sure <rev> names an
object that exists, without requiring <rev> to be a tag, and
without dereferencing <rev> ; because a tag is already an object,
it does not have to be dereferenced even once to get to an object. <rev>^{tag} can be used to ensure that <rev> identifies an
existing tag object.


[System] You are a helpful assistant.

[User]
Git Remove unwanted commits from a Pull Request
I have started working on a project and I made some unwanted commits which I pushed to origin master. Now, when I try to do a pull request, Github wants to commit all of the previous commits.
My question is, how do I remove the unwanted commits and commit the changes that I want to commit so that I am up to date with master?

[Assistant]
I assume your origin is your own fork of some project that you want to do a pull request too?
Since you will be changing history (by resetting the head) you will need to push with --force flag. Locate the hash of your last good commit using git log.
Now run
git reset SHA

This will change your head to that sha and preserve the changes in the files since that last good commit, your index will also be reset.
Now you can change your code and do the commits you want. But you have to do git push --force since you changed the history of the repository. This means that anyone who forked your repository won't be able to pull changes from you anymore. But you will be able to do a pull request to your upstream.


[System] You are a helpful assistant.

[User]
git: 'credential-cache' is not a git command
I followed these instructions to the letter, including the part about password caching. It seems like the instructions are wrong, because every time I git push origin master I get this error:
git: 'credential-cache' is not a git command. See 'get --help'.

... at which point I am forced to enter my username and password. After doing so, I am presented with the same error message again, followed by the output from git push.
Here is the contents of my .gitconfig file:
[user]
    name = myusername
    email = [email protected]
[credential]
    helper = cache

To be clear, after I installed Git and ran Git Bash, here is exactly what I typed:
git config --global user.name "myusername"
git config --global user.email "[email protected]"
git config --global credential.helper cache

Please help. This is so frustrating!

[Assistant]
From a blog I found:

This [git-credential-cache] doesn’t work for Windows systems as git-credential-cache communicates through a Unix socket.

Git for Windows
Since msysgit has been superseded by Git for Windows, using Git for Windows is now the easiest option. Some versions of the Git for Windows installer (e.g. 2.7.4) have a checkbox during the install to enable the Git Credential Manager. Here is a screenshot:

Still using msysgit? For msysgit versions 1.8.1 and above
The wincred helper was added in msysgit 1.8.1. Use it as follows:
git config --global credential.helper wincred

For msysgit versions older than 1.8.1
First, download git-credential-winstore and install it in your git bin directory.
Next, make sure that the directory containing git.cmd is in your Path environment variable. The default directory for this is C:\Program Files (x86)\Git\cmd on a 64-bit system or C:\Program Files\Git\cmd on a 32-bit system. An easy way to test this is to launch a command prompt and type git. If you don't get a list of git commands, then it's not set up correctly.
Finally, launch a command prompt and type:
git config --global credential.helper winstore

Or you can edit your .gitconfig file manually:
[credential]
    helper = winstore

Once you've done this, you can manage your git credentials through Windows Credential Manager which you can pull up via the Windows Control Panel.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  core.maxTreeDepth

[Assistant]
The maximum depth Git is willing to recurse while traversing a
tree (e.g., "a/b/cde/f" has a depth of 4). This is a fail-safe
to allow Git to abort cleanly, and should not generally need to
be adjusted. The default is 4096.


[System] You are a helpful assistant.

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

[Assistant]
Specifies how many context lines should be used in calls to diff
made by the git-gui . The default is "5".


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-checkout-index

[Assistant] Copy files from the index to the working tree


[System] You are a helpful assistant.

[User]
Git push won't do anything (everything up-to-date)
I'm trying to update a Git repository on GitHub. I made a bunch of changes, added them, committed then attempted to do a git push. The response tells me that everything is up to date, but clearly it's not.
git remote show origin

responds with the repository I'd expect.
Why is Git telling me the repository is up to date when there are local commits that aren't visible on the repository?
  [searchgraph]  git status
# On branch develop
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       Capfile
#       config/deploy.rb
nothing added to commit but untracked files present (use "git add" to track)

  [searchgraph]  git add .

  [searchgraph]  git status
# On branch develop
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   Capfile
#       new file:   config/deploy.rb
#

  [searchgraph]  git commit -m "Added Capistrano deployment"
[develop 12e8af7] Added Capistrano deployment
 2 files changed, 26 insertions(+), 0 deletions(-)
 create mode 100644 Capfile
 create mode 100644 config/deploy.rb

  [searchgraph]  git push
Everything up-to-date

  [searchgraph]  git status
# On branch develop
nothing to commit (working directory clean)

[Assistant]
git push doesn't push all of your local branches: how would it know which remote branches to push them to? It only pushes local branches which have been configured to push to a particular remote branch.
On my version of Git (1.6.5.3), when I run git remote show origin it actually prints out which branches are configured for push:
Local refs configured for 'git push':
  master pushes to master (up to date)
  quux   pushes to quux   (fast forwardable)

Q. But I could push to master without worrying about all this!
When you git clone, by default it sets up your local master branch to push to the remote's master branch (locally referred to as origin/master), so if you only commit on master, then a simple git push will always push your changes back.
However, from the output snippet you posted, you're on a branch called develop, which I'm guessing hasn't been set up to push to anything.  So git push without arguments won't push commits on that branch.
When it says "Everything up-to-date", it means "all the branches you've told me how to push are up to date".
Q. So how can I push my commits?
If what you want to do is put your changes from develop into origin/master, then you should probably merge them into your local master then push that:
git checkout master
git merge develop
git push             # will push 'master'

If what you want is to create a develop branch on the remote, separate from master, then supply arguments to git push:
git push origin develop

That will: create a new branch on the remote called develop; and bring that branch up to date with your local develop branch; and set develop to push to origin/develop so that in future, git push without arguments will push develop automatically.
If you want to push your local develop to a remote branch called something other than develop, then you can say:
git push origin develop:something-else

However, that form won't set up develop to always push to origin/something-else in future; it's a one-shot operation.


[System] You are a helpful assistant.

[User]
git ls-files: howto identify new files (added, not committed)?
After I called git add <file> the command git status will show me something like:
...
new file:    <file>

Somehow I can't manage it to get the same information by using ls-files, it (ls-files -tc in this case) will show me:
H <commited file>
H <other commited file>
H <file>

There seems no commandline switch to exist for new files. The file is reported as cached, which is ok, but how do I find out that it is not committed at this time?
Is this possible with ls-files or some similar command (where I do not have to parse a lot of output like in the case of git status)?

[Assistant]
You want to use git diff --cached.  With --name-only it'll list all the files you've changed in the index relative to HEAD.  With --name-status you can get the status symbol too, with --diff-filter you can specify which set of files you want to show ('A' for newly added files, for instance).  Use -M to turn on move detection and -C for copy detection if you want them.
For the strictest reading of what you wrote, git diff --cached --name-only --diff-filter=A will list all the files you've added since HEAD which don't exist in HEAD.


[System] You are a helpful assistant.

[User]
github: No supported authentication methods available
i use github and have successfully added and synched files on my laptop in the past.
as of recent i started getting "PuTTY Fatal Error: Disconnected: No supported authentication methods available" after running:
git pull origin master (or push)
however
ssh [email protected] returns the correct response:
ERROR: Hi username! You've successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.
after digging around on github i found this morcel:
No supported authentication methods available
You should be aware of the environment variable GIT_SSH, which is used by git to find your ssh-speaking client, if ssh doesn’t work for you. The git install may be using plink.exe (via GIT_SSH) to perform the authentication. If so, make sure you have pageant.exe running, and the key you created for github loaded into it. This provides the key to plink.exe; without it, the above error will occur.
not sure what plink.exe or peagant.exe is.. and the fact that ssh [email protected] seems to authenticate correctly makes me wonder what the best solution here is.. i certainly don't want to overcomplicate my setup if not necessary.

[Assistant]
You can create a file named ".profile" in your home directory, for me that's C:\Users\[user]
Inside that file, put the following line of code:
GIT_SSH="/usr/bin/ssh.exe"

This will set the GIT_SSH environment variable to use the ssh client included with git.
The .profile script gets executed when you start your Git Bash command line.
Edit:
This is my .profile. It will ask you for your password the first time you start the git command prompt, then will remember it from then on, until you reboot your computer. Very handy so you don't have to keep entering your password each time you want to do something.
SSH_ENV="$HOME/.ssh/environment"
GIT_SSH="/usr/bin/ssh.exe"

function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}

# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cygwin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi


[System] You are a helpful assistant.

[User]
Haskell Stack install package dependency from github

Is it possible to install a version of a package from github using Haskell stack?
e.g. in a .cabal or a stack.yaml file, how can I point a dependency at a git repo/branch/revision?

[Assistant]
For stack <1.11:
The documentation for the stack.yaml packages section gives examples of referring to more complex package locations.

packages:
- location: .
- location: dir1/dir2
- location: https://example.com/foo/bar/baz-0.0.2.tar.gz
- location: http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip
- location:
    git: [email protected]:commercialhaskell/stack.git
    commit: 6a86ee32e5b869a877151f74064572225e1a0398
- location:
    hg: https://example.com/hg/repo
    commit: da39a3ee5e6b4b0d3255bfef95601890afd80709

Then add extra-dep: true to the package entry just to tell stack not to treat the code it pulls in as something you're developing on (e.g., don't load it in GHCi).


[System] You are a helpful assistant.

[User]
Create a branch in Git from another branch
I have two branches: master and dev
I want to create a "feature branch" from the dev branch.
Currently on the branch dev, I do:
git checkout -b myfeature dev

... (some work)
git commit -am "blablabla"
git push origin myfeature

But, after visualizing my branches, I got:
--**master**
------0-----0-----0-----0-----0
------------------------**dev**----**myfeature**

I mean that the branch seems fast-forward merged, and I don't understand why...
What am I doing wrong?
How can you branch off from another branch and push back to the remote repository for the feature branch?
All that in a branching model like the one described here.

[Assistant]
If you like the method in the link you've posted, have a look at Git Flow.
It's a set of scripts he created for that workflow.
But to answer your question:
git checkout -b myFeature dev

Creates the MyFeature branch off dev. Do your work and then
git commit -am "Your message"

Now merge your changes to dev without a fast-forward
git checkout dev
git merge --no-ff myFeature

Now push the changes to the server
git push origin dev
git push origin myFeature

And you'll see it how you want it.


[System] You are a helpful assistant.

[User]
How can I overwrite or replace a commit with new one once I have pushed to remote?

So I'm working on a sensitive project with a group and all our sources are on Github. I recently pushed a commit and later realized there were lot of mistakes in my push. I've since fixed all those mistakes on my local copy and am about to push again. However is there any way I can push and overwrite my last commit? My reason being, I don't want the others to look up my initial commit and the changes it had...
Basically I want to overwrite the old commit with my new one.. so no information about the old commit remains for other group members to see.

[Assistant]
Usually, once something is out on Github (or a public repo), there's no way to make sure no one else has the bad commit.
If you simply want cleaner code history though, the way to do what you ask requires you to overwrite history both locally and on the remote project.
What you want is to either do a git commit --amend to modify your old commit if you've not already created a fresh commit with your changes.
If you've already created a fresh commit, you'll want to use git rebase -i to squash your commit on top of the old one.
After you've made this change locally, and verified your commit looks the way you want it to, you'll have to git push --force to overwrite history on the Github remote.
Here's a tutorial on how to re-write history in git, it explains both the approaches listed in this answer.


[System] You are a helpful assistant.

[User]
Github commit message links
Is it possible to create a commit message with link to other repository commit?
Eg. something like [Username\Repo\commitHash]
Usage example: if some bc break would happen in some framework's commit, I'd like to link to this very commit in my own commits updating my code which uses this framework.

[Assistant]
I was searching for something like this myself. Found it on:
https://help.github.com/articles/autolinked-references-and-urls/#commit-shas
<<username>>/<<repo>>@<<commitHash>>

Without the angle brackets of course :)


[System] You are a helpful assistant.

[User]
Update shared forked repository using git

Consider repository A a github repository that is managed via Gerrit.
I cloned repository A and I created a new branch starting from the master branch of repository A. I pushed this new branch on a new gitlab repository B. I am admin on repository B and I shared it with other developers. Developers cannot push on this branch, but I can merge theirs pull requests.
I merged some pull requests on the master branch of repository B. So, repository B has the initial commits of repository A and new commits of the pull request: B commits on top of A commits (b a).
Then, I want to update the repository B with new commits of repository A.   Call these commits a+.
I see two options:

If I merge A on B, the result is: a+ b a.
If I rebase B on A+, the results is: b a+ a.

Option 1: the developments commits are mixed with external ones. Difficult to debug and to highlight differences.
Option 2: I have to push force the changes on the the remote B. The consequences, if I am not mistaken, may be:
 1. if developers pull B and they have commits on local master of B, they will lose their local changes;
 2. developers may face big troubles during rebase their local branches after the forced update of branch B.
How should I proceed to avoid any problems?

[Assistant]
If I understand it correctly, you have a single (local) repository which looks somewhat like this:
            A/master
               ↓
* -- * -- * -- a
                \
                 * -- * -- b
                           ↑
                       B/mybranch

Now, A is updated, so it looks like this:
                          A/master
                              ↓
* -- * -- * -- a -- * -- * -- a+
                \
                 * -- * -- b
                           ↑
                       B/mybranch

Note here that you have two diverged branches that are not in a straight line. So saying that you would get a+ b a when you merge A onto B is not correct. You do get a merge, but that keeps the history as it is:
                          A/master
                              ↓
* -- * -- * -- a -- * -- * -- a+
                \               \
                 * -- * -- b --- M
                                 ↑
                            B/mybranch

As you can see, you still have the information where the commits came from: The ones between a and a+ came from one branch, and the other ones between a and b came from another. And M combines those tro branches. Usually, this is exactly the proper way to solve this.
The benefit of this over rebasing—as you noticed yourself—is that the commits stay the way they are. All users who have interacted with either repository can simply pull those changes in without any problems. If you rebased any of those commits, they would have to manually fix that (chances are that they don’t even realize it, so they will just pull and actually create an even messier history with duplicate commits).
So a merge is definitely better to work with here. Yes, the history will not look as perfect as a straight line, but it properly conveys what has happened: There is a diverged development line which is independent and that has then been updated with the changes from the upstream repository A. This information can be useful and as such it makes sense to keep them in. And especially if you have users interacting with both those remotes, they will definitely prefer to keep their repository compatible with both remotes.
If you don’t want the history to look like this, and don’t care about compatibility with A, you could also squash all the changes from A onto your B:
                          A/master
                              ↓
* -- * -- * -- a -- * -- * -- a+
                \
                 * -- * -- b -- [A]
                                 ↑
                            B/mybranch

Here, [A] is a squashed commit that contains all the changes between a and a+ in a single commit. You could get this result by rebasing A onto B while squashing all commits. In this case, you should clearly state where those changes come from in the commit message though.


[System] You are a helpful assistant.

[User] git-pull - Fetch from and integrate with another repository or a local branch  -j  --jobs=<n>

[Assistant]
Number of parallel children to be used for all forms of fetching. If the --multiple option was specified, the different remotes will be fetched
in parallel. If multiple submodules are fetched, they will be fetched in
parallel. To control them independently, use the config settings fetch.parallel and submodule.fetchJobs (see git-config ). Typically, parallel recursive and multi-remote fetches will be faster. By
default fetches are performed sequentially, not in parallel.


[System] You are a helpful assistant.

[User]
How can I have linked dependencies in a git repo?
In my scripts, I often use libraries (mine or others') that have their own repos. I don't want to duplicate those in my repo and get stuck with updating them every time a new version comes out.
However, when somebody clones the repo, it should still work locally and not have broken links.
Any ideas about what I could do?

[Assistant]
You can do this with submodules in git. In your repository, do:
git submodule add path_to_repo path_where_you_want_it

So, if the library's repository had a URL of git://github.com/example/some_lib.git and you wanted it at lib/some_lib in your project, you'd enter:
git submodule add git://github.com/example/some_lib.git lib/some_lib

Note that this needs to be done from the top-level directory in your repository. So don't cd into the directory where you're putting it first.
After you add a submodule, or whenever someone does a fresh checkout of your repository, you'll need to do:
git submodule init
git submodule update

And then all submodules you've added will be checked out at the same revision you have.
When you want to update to a newer version of one of the libraries, cd into the submodule and pull:
cd lib/some_lib
git pull

Then, when you do a git status you should see lib/somelib listed in the modified section. Add that file, commit, and you're up to date. When a collaborator pulls that commit into their repository, they'll see lib/somelib as modified until they run git submodule update again.


[System] You are a helpful assistant.

[User]
Multiple ssh keys are not working

OS Description: Ubuntu 14.04.3 LTS
ssh: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3, OpenSSL 1.0.1f 6 Jan 2014

I am unable to use multiple ssh key for gitlab. The error I am getting is
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.

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

I am pretty much sure that I did everything right
This is my config file
Host work gitlab.com
    Hostname gitlab.com
    IdentityFile ~/.ssh/ida_rsa
    User git

Host integrate gitlab.com
    Hostname gitlab.com
    IdentityFile ~/.ssh/ida_rsa_personal
    User git

The keys are added automatically in ssh-agent, but to make sure I also added the key manually
$ ssh-add -l
2048 e7:08:d6:8c:00:28:31:f9:3f:21:4a:0f:4e:1e:ee:20 id_rsa (RSA)
2048 ff:22:f6:90:2b:7c:9f:ed:45:41:df:79:06:de:fe:81 id_rsa_personal (RSA)

My ssh-agent is also running
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-uTC6tA5HMt1x/agent.4899; export SSH_AUTH_SOCK;
SSH_AGENT_PID=4900; export SSH_AGENT_PID;
echo Agent pid 4900;

Permissions of ssh key
-rw-------  1 yogi yogi  1679 jun 25 15:38 id_rsa
-rw-------  1 yogi yogi  1679 ago 25 10:53 id_rsa_personal
-rw-r--r--  1 yogi yogi   404 ago 25 10:53 id_rsa_personal.pub
-rw-r--r--  1 yogi yogi   391 jun 25 15:41 id_rsa.pub

I added my ssh public key on gitlab.
Could any one please tell me what I am missing ?
Note :-
I noticed that out of my two ssh keys, the ssh key which is on top( id_rsa - e7:08....) works fine.
$ ssh-add -l
**2048 e7:08:d6:8c:00:28:31:f9:3f:21:4a:0f:4e:1e:ee:20 id_rsa (RSA)**
2048 ff:22:f6:90:2b:7c:9f:ed:45:41:df:79:06:de:fe:81 id_rsa_personal (RSA)

If I add id_rsa_personal(ff:22..) after id_rsa, than id_rsa_personal starts working fine and id_rsa stops working.
$ ssh-add -l
**2048 ff:22:f6:90:2b:7c:9f:ed:45:41:df:79:06:de:fe:81 id_rsa_personal (RSA)**
2048 e7:08:d6:8c:00:28:31:f9:3f:21:4a:0f:4e:1e:ee:20 id_rsa (RSA)

I think , ssh-agent is unable to iterate through keys. It only reads first key and stops.
Is this a bug in openssh ? If yes, any workaround ?
Thanks

[Assistant]
You need to have ~/.ssh/config file
Inside file
# Default GitHub user
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/personalid

# Work user account
Host bitbucket.org
    HostName bitbucket.org
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/workid

Details can be found in the link below
https://confluence.atlassian.com/bitbucket/configure-multiple-ssh-identities-for-gitbash-mac-osx-linux-271943168.html
If the domain is same, use different Host
Host work.gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa.work

Host home.gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa.home

Clear the cache
ssh-add -D

Add all ssh keys
ssh-add ~/.ssh/id_rsa.work
ssh-add ~/.ssh/id_rsa.home

Also set your repos' url in (.git/config) accordingly as given:
url = [email protected]:xxxxxxxxxx.git
url = [email protected]:yyyyyyyyy.git

If your ssh config file is as what I suggested.


[System] You are a helpful assistant.

[User]
Golang, importing packages from Github requests me to remember the Github URL?

I'm very new to Golang. I see that in Golang you can import packages directly from Github like:
import "github.com/MakeNowJust/heredoc"

Does that mean I have to remember this URL in order to use this package? IMHO this is not cool. What if later the author of the package removed it or changed the URL? Any ideas?

[Assistant]
I would recommend you to read the How to Write Go Code documentation and this blog post.
The path you're seeing in your import line is not a url, but only the path the package is located in (normally relative to $GOROOT/src/pkg or $GOPATH/src). So your package heredoc is most probably located in the directory $GOPATH/src/github.com/MakeNowJust/heredoc.
The recommended way to use external packages is by downloading and installing them via go get. You might want to check out the documentation of go get by go get --help.


[System] You are a helpful assistant.

[User]
What is the difference between GitHub Flow and GitLab Flow?
Recently I've found three concepts of a workflow in Git:

GitFlow
GitHub Flow
GitLab Flow

I've read the nice articles about it but I don't understand GitLab Flow very well.
Briefly.
GitFlow

We've a master branch as a production branch. Also we have a develop branch where every developer merges his features. Sometimes we create a release branch to deploy our features in production. If we have a bug in the release branch, fix it and pull changes into the develop branch. If we have a critical bug in production, create new hotfix-branch, fix the bug and merge branch with production (master) and develop branches.
This approach works well if we seldom publish results of our work. (Maybe once every 2 weeks).
GitHub Flow

We have a master branch as a production branch. And we (as developers) can  create branches for adding new features or fixing bugs and merge them with production (master) branch. It sounds very simple. This approach fits for extreme programming where the production branch is deployed several times in a day.
GitLab Flow

I've seen new terms like a pre-production, a production, a release (stable) branch and a staging environment, a pre-production environment, a production environment. What relationships do they have between them?
I understand it this way: If we need to add a new feature we deploy a pre-production branch from the master branch. When we have finished the feature, we deploy a production branch from the pre-production branch. A pre-production branch is the intermediate stage. And then the master branch pulls all changes from the production branch.
The approach is good if we want to see each separate feature; we just checkout in the branch what we need to look at.
But if we need to show our work we create a release branch with a tag as late as possible. If later we fix bugs in the master branch we need to cherry-pick them to the last release branch. At the end we have the release branch with tags that can help us to move between versions.
Is my understanding correct?
What is the difference between pull and cherry-pick?

[Assistant]
It has been a year now since this post was raised, but considering future readers and the fact things have changed a bit I think it's worth refreshing.
GitHub Flow as originally depicted by Scott Chacon in 2011 assumed each change once reviewed on a feature branch and merged into master should be deployed to production immediately. While this worked at the time and conformed to the only GitHub Flow rule, which is anything in the master branch is deployable, it was quickly discovered that in order to keep master a true record of known working production code the actual deployment to production should happen from the feature branch before merging it into master. Deploying from the feature branch makes perfect sense as in the case of any issue production can be instantaneously reverted by deploying master to it. Please take a look at a short visual introduction to GitHub Flow.
GitLab Flow is kind of an extension to GitHub Flow accompanied by a set of guidelines and best practices that aim to further standardize the process. Aside from promoting ready to deploy master branch and feature branches (same as GitHub Flow) it introduces three other kinds of branches:

Production branch
Environment branches: uat, pre-production, production
Release branches: 1-5-stable, 1-6-stable

I believe above names and examples are self-descriptive, thus I won't elaborate further.