[System] You are a helpful assistant.

[User]
How to integrate UML diagrams into GitLab or GitHub

I want to publish some programming documentation I have in a public available repository. This documentation has formatted text, some UML diagrams, and a lot of code examples. I think that GitHub or GitLab are good places to publish this.
To publish the UML diagrams, I would like to have some easy way to keep them updated into the repository and visible as images in the wiki. I don't want to keep the diagrams in my computer (or on the cloud), edit them, generate an image, and then publish it every time.
Is there a way to put the diagrams in the repository (in PlantUML syntax would be ideal), link them in the markdown text, and make the images auto-update every time the diagram is updated?

[Assistant]
Edit: Alternative with Proxy service
This way is significantly different and simpler than the answer below; it uses the PlantUML proxy service:
http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.github.com/plantuml/plantuml-server/master/src/main/webapp/resource/test2diagrams.txt

The GitHub markdown for this would be:
![alternative text](http://www.plantuml.com/plantuml/proxy?cache=no&src=https://raw.github.com/plantuml/plantuml-server/master/src/main/webapp/resource/test2diagrams.txt)

This method suffers from not being able to specify the SVG format (it defaults to PNG), and it is perhaps not possible to work-around the caching bug mentioned in the comments.

After trying the other answer, I discovered the service to be slow and seemingly not up to the latest version of PlantUML.
I've found a different way that's not quite as straightforward, but it works via  PlantUML.com's server (in the cloud). As such, it should work anywhere you can hotlink to an image.
It exploits the !includeurl function and is essentially an indirection. The markdown file links to a PlantUML source that includes the diagram's source. This method allows modifying the source in GitHub, and any images in the GitHub markdown files will automatically update. But it requires a tricky step to create the URL to the indirection.

Get the URL to the raw PlantUML source, e.g., https://raw.githubusercontent.com/linux-china/plantuml-gist/master/src/main/uml/plantuml_gist.puml (using the example in the joanq's answer)

Go to http://plantuml.com/plantuml/form (or PlantText.com) and create a one-line PlantUML source that uses the !includeurl URL-TO-RAW-PLANTUML-SOURCE-ON-GITHUB operation. Continuing with the example URL, the PlantUML (meta)source is:
!includeurl https://raw.githubusercontent.com/linux-china/plantuml-gist/master/src/main/uml/plantuml_gist.puml

Copy the image URL from PlantUML.com's image, e.g., http://plantuml.com:80/plantuml/png/FSfB2e0m303Hg-W1RFPUHceiDf36aWzwVEl6tOEPcGGvZXBAKtNljW9eljD9NcCFAugNU15FU3LWadWMh2GPEcVnQBoSP0ujcnS5KnmaWH7-O_kEr8TU and paste it into your GitHub markdown file. This URL won't change.
![PlantUML model](http://plantuml.com:80/plantuml/png/3SNB4K8n2030LhI0XBlTy0YQpF394D2nUztBtfUHrE0AkStCVHu0WP_-MZdhgiD1RicMdLpXMJCK3TC3o2iEDwHSxvNVjWNDE43nv3zt731SSLbJ7onzbyeF)

Bonus: You can even get access to the SVG format by modifying the plantuml/png/ part of the URL to be plantuml/svg/ as follows
![PlantUML model](http://plantuml.com:80/plantuml/svg/3SNB4K8n2030LhI0XBlTy0YQpF394D2nUztBtfUHrE0AkStCVHu0WP_-MZdhgiD1RicMdLpXMJCK3TC3o2iEDwHSxvNVjWNDE43nv3zt731SSLbJ7onzbyeF)

Example on GitHub
https://github.com/fuhrmanator/course-activity-planner/blob/master/ooad/overview.md
Caveat with private repos
As davidbak pointed out in a comment, the raw file in a private repo will have a URL with token=<LONGSTRINGHERE> in it, and this token changes as the source file updates. Unfortunately, the markdown breaks when this happens, so you have to update the Readme file after you commit the file to GitHub, which is not a great solution.


[System] You are a helpful assistant.

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

[Assistant]
Whether to print the diffstat between ORIG_HEAD and the merge result
at the end of the merge.  True by default.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --remove-empty

[Assistant] Stop when a given path disappears from the tree.


[System] You are a helpful assistant.

[User]
In gitlab, how to set "pipelines must succeed" only for specific branches but not others for a merge request to merge?

In the merge checks settings, I have enabled the "pipelines must succeed" option:

But the branches without any jobs are stuck at merge by saying "waiting for pipelines status" and you can't merge without a successful pipeline.
Can I enable the "pipelines must succeed" option only for some specific branches like master/production?

[Assistant]
As a workaround, you can trigger a merge request pipeline from the branches that don't currently have any jobs. The pipeline can have a single job that always passes. A merge request pipeline will only be created after a MR is created, not before.
A simple job like this should work:
print-info:
  stage: setup
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
  script:
    - 'echo "Job start: $CI_JOB_STARTED_AT"'
    - 'echo "Branch: $CI_COMMIT_BRANCH"'
    - 'echo "Commit Author: $CI_COMMIT_AUTHOR"'

Note: I'm not sure what your current pipeline looks like, so you may have to change the rules section to suit your needs.


[System] You are a helpful assistant.

[User]
Git LFS track folder recursively
Is it possible to track recursively all files contained in a folder and its subfolders with Git LFS ?
I would like to do something like this :
git lfs track myfolder/*

[Assistant] Use git lfs track "myfolder/**", with quotes to avoid the shell already expanding the pattern. All that the track command does is to write to .gitattributes, which in turn uses (almost) the same pattern matching rules as .gitignore, see the PATTERN FORMAT description.


[System] You are a helpful assistant.

[User] gitfaq - Frequently asked questions about using Git  How do I configure a different editor?

[Assistant]
If you haven’t specified an editor specifically for Git, it will by default
use the editor you’ve configured using the VISUAL or EDITOR environment
variables, or if neither is specified, the system default (which is usually vi ).  Since some people find vi difficult to use or prefer a different
editor, it may be desirable to change the editor used. If you want to configure a general editor for most programs which need one, you
can edit your shell configuration (e.g., ~/.bashrc or ~/.zshenv ) to contain
a line setting the EDITOR or VISUAL environment variable to an appropriate
value.  For example, if you prefer the editor nano , then you could write the
following: export VISUAL=nano If you want to configure an editor specifically for Git, you can either set the core.editor configuration value or the GIT_EDITOR environment variable.  You
can see git-var for details on the order in which these options are
consulted. Note that in all cases, the editor value will be passed to the shell, so any
arguments containing spaces should be appropriately quoted.  Additionally, if
your editor normally detaches from the terminal when invoked, you should specify
it with an argument that makes it not do that, or else Git will not see any
changes.  An example of a configuration addressing both of these issues on
Windows would be the configuration "C:\Program Files\Vim\gvim.exe" --nofork ,
which quotes the filename with spaces and specifies the --nofork option to
avoid backgrounding the process.


[System] You are a helpful assistant.

[User] git-branch - List, create, or delete branches  --abbrev=<n>

[Assistant]
In the verbose listing that show the commit object name,
show the shortest prefix that is at least <n> hexdigits
long that uniquely refers the object.
The default value is 7 and can be overridden by the core.abbrev config option.


[System] You are a helpful assistant.

[User]
Shortcuts for git commands
I would like to use shortcuts or aliases for git commands.
git diff
git status
git push
git pull
git stash
git branch -a

How do I create shortcuts or aliases, is there a predefined list?

[Assistant]
Put this into your .gitconfig
[alias]
  st = status
  ci = commit
  br = branch
  co = checkout

You can add as much as you want


[System] You are a helpful assistant.

[User]
Does git ignore empty folders?
I created an Android project, added it to my git repo, comitted and pushed my clone to the master. Later I tried checking out the project and Eclipse complained about missing src folders. I checked my repo and the master repo and the src folders are missing (Im sure they were there when I created the project). So can someone explain what happened here? Im new to git so maybe I missed something?

[Assistant]
Git doesn't ignore empty directories. It ignores all directories. In Git, directories exist only implicitly, through their contents. Empty directories have no contents, therefore they don't exist.
Or to put it another way: Git is a content tracker. Empty directories are not content.


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  SCM

[Assistant] Source code management (tool).


[System] You are a helpful assistant.

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

[Assistant]
DESCRIPTION Create, unpack, and manipulate "bundle" files. Bundles are used for
the "offline" transfer of Git objects without an active "server"
sitting on the other side of the network connection. They can be used to create both incremental and full backups of a
repository, and to relay the state of the references in one repository
to another. Git commands that fetch or otherwise "read" via protocols such as ssh:// and https:// can also operate on bundle files. It is
possible git-clone a new repository from a bundle, to use git-fetch to fetch from one, and to list the references
contained within it with git-ls-remote . There’s no
corresponding "write" support, i.e.a git push into a bundle is not
supported. See the "EXAMPLES" section below for examples of how to use bundles.


[System] You are a helpful assistant.

[User]
My Git repository is in the wrong root directory. Can I move it? (../ instead of ./)
Somehow when I git inited my latest project a month or so ago I ran the command in the directory one directory higher than the root of my project.
So my repository is in the ./project directory and not the ./project/my-new-project directory.  I don't know how I didn't realize the issue earlier, but I just never looked for the .git directory until now.
Is there a way, without killing my project, to move the repository to the proper directory and then tell git what the new base of the project is?  Just moving the directory doesn't work.  Git thinks all files have been deleted.

[Assistant]
I had the opposite problem - had to shift the git root to the parent directory (from project/src to project)
To my extreme surprise, the following worked!!
src$ mv .git ../
src$ cd ..
project$ git add src
project$ git commit -a

git cleverly detected that all the new files were renamed versions of old ones and no history was lost
You can try something similar... move the .git folder and add the files again before committing


[System] You are a helpful assistant.

[User]
High memory usage for Gitlab CE

Look at this picture showing gitlab ce memory consumption.

I really dont need all of those workers, sidekiq or unicorn or all of those daemon. This is on IDLE. I mean, I installed this to manage 1 project, with like 4 people, I dont need all those daemon. Is there any way to reduce this ?

[Assistant]
I also had problems with gitlab's high memory consumption. So I ran the linux tool htop.
In my case I found out that the postgresl service used most of the memory.
With postgres service running 14.5G of 16G were used
I stopped one gitlab service after the other and found out that when I stop postgres a lot of memory was freed.

You can try it
gitlab-ctl stop postgresql

and start the service again with
gitlab-ctl start postgresql

Finally I came across the following configuration in /etc/gitlab/gitlab.rb
##! **recommend value is 1/4 of total RAM, up to 14GB.**
# postgresql['shared_buffers'] = "256MB"

I just set the shared buffers to 256MB by removing the comment #, because 256MB is sufficient for me.
postgresql['shared_buffers'] = "256MB"

and executed gitlab-ctl reconfigure. gitlab-ctl restarts the affected services and the memory consumption is now very moderate.

Hopefully that helps someone else.


[System] You are a helpful assistant.

[User]
Why is github asking me username/password although I setup SSH authentication?

I have followed these instructions to set up the SSH key for github. But now when I do
> git pull
Username for 'https://github.com':

in a repository on the local computer I have taken the public SSH key from, I am still asked for a username/password. Did I miss a step?

[Assistant]
You need to tell Git to use SSH protocol instead of HTTPS. On the repository page on GitHub, select Clone or Download and Use SSH. You will get a URL for the SSH protocol in the form [email protected]:<user>/<repo>.git.
Then run the following command in your working tree to tell Git to use this URL instead of the current one:
git remote set-url origin [email protected]:<user>/<repo>.git

This is also explained in the GitHub Help.
The method above won’t cause the repository to be cloned again, it just changes the communication protocol used for future synchronization between your local repo and GitHub.
Alternatively, you could set up a new remote using git remote add <new-remote-name> <url> and then git pull <new-remote-name> but Git would keep track of both protocols as separate remotes, so I do not recommend this.


[System] You are a helpful assistant.

[User]
How to switch back to 'master' with git?
I have made my first commit; then created a branch (let's say branch1).
In this branch I've created a directory 'example' and commited. In GitHub I see my new branch and the new directory 'example' that I have added.
Now I wonder how can I 'sync' back to master; and so have the 'example' folder deleted (as it doesn't exist on master).
EDIT : find . -type d -empty -exec touch {}/.gitignore \;
did the job.

[Assistant]
You need to checkout the branch:
git checkout master

or
git checkout main

See the Git cheat sheets for more information.
Edit: Please note that git does not manage empty directories, so you'll have to manage them yourself. If your directory is empty, just remove it directly.


[System] You are a helpful assistant.

[User]
git pull error "The requested URL returned error: 503 while accessing"

I've been facing problems accessing my git repository lately.  It worked perfectly fine earlier but now I cannot run any command on CLI. I can however, access the corresponding Web Page, Could someone help me how to resolve this issue?

[Assistant]
Had the same error while using SourceTree connected to BitBucket repository.
When navigating to repository url on bitbucket.org the warning message appeared:

This repository is in read-only mode. You caught us doing some quick maintenance.

After around 2 hours repository was accessible again.
You can check status and uptime of bitbucket here:
http://status.bitbucket.org/


[System] You are a helpful assistant.

[User]
TortoiseGit: How can I see a list of commits that are about to be pushed
I have merged in some commits from different branches into my "develop" branch and I'm now ready to push them to the remote branch.
In TortoiseGit, is it possible to view a list of items that are about to be pushed?
"Check for Modifications" is not showing me anything, as the changes are coming from branches.
"Show Log" is also showing me a chronological list of all changes. I rather just see a simple list of items that are queued to be pushed.
I hope I'm making sense.

[Assistant]
Use "Sync Dialog"
Right click the repository folder, choose "Sync"
In "Out commits" tab, you will see a list of commits to be pushed to the remote.
Switch to "Out ChangeList" tab, you will see a list of changed files relative to the remote version.
If "Out commits" is empty or "Out ChangeList" tab does not appear, specify "remote branch" explicitly in the combo box.
Then "Out commits" list will load and "Out ChangeList" tab will appear.
This may happen if current branch does not have a "remote-tracking branch".
"Pull Dialog" has no such info.


[System] You are a helpful assistant.

[User] git-bisect - Use binary search to find the commit that introduced a bug  --no-checkout

[Assistant]
Do not checkout the new working tree at each iteration of the bisection
process. Instead just update the reference named BISECT_HEAD to make
it point to the commit that should be tested. This option may be useful when the test you would perform in each step
does not require a checked out tree. If the repository is bare, --no-checkout is assumed.


[System] You are a helpful assistant.

[User]
Can git automatically switch between spaces and tabs?
I use tabs for indentation in my python programs, but I would like to collaborate (using git) with people who use spaces instead.
Is there a way for git to automatically convert between spaces and tabs (say, 4 spaces = 1 tab) on pushing/fetching? (similar to the CR/LF conversion)

[Assistant]
Here is the complete solution:
In your repository, add a file .git/info/attributes which contains:
*.py  filter=tabspace

Linux/Unix
Now run the commands:
git config --global filter.tabspace.smudge 'unexpand --tabs=4 --first-only'
git config --global filter.tabspace.clean 'expand --tabs=4 --initial'

OS X
First install coreutils with brew:
brew install coreutils

Now run the commands:
git config --global filter.tabspace.smudge 'gunexpand --tabs=4 --first-only'
git config --global filter.tabspace.clean 'gexpand --tabs=4 --initial'

All systems
You may now check out all the files of your project. You can do that with:
git checkout HEAD -- **

and all the python files will now have tabs instead of spaces.
Edit: changed the forced checkout command. You should commit your work first, of course.


[System] You are a helpful assistant.

[User] git-rev-parse - Pick out and massage parameters  --show-ref-format

[Assistant] Show the reference storage format used for the repository.


[System] You are a helpful assistant.

[User]
How long does it take GitHub page to update after changing index.html?

I am just wondering how long does it take for GitHub page to show the new items that I have added to the repository.
I changed index.html but after 10 minutes it still showed up the previous page...

[Assistant]
The first time you generate your site it will take about 10 minutes for it to show up. Subsequent builds take only seconds from the time you push the changes to your GitHub repository.
However, depending on how your have your domain configured, there may be extra time for the CDN cache to break.
Note: using a subdomain, such as yourproject.github.io is the recommended domain setup, but does mean page builds take longer to show up since it has the benefit of using the GitHub CDN.


[System] You are a helpful assistant.

[User] git-am - Apply a series of patches from a mailbox  -c  --scissors

[Assistant]
Remove everything in body before a scissors line (see git-mailinfo ). Can be activated by default using
the mailinfo.scissors configuration variable.


[System] You are a helpful assistant.

[User]
How to use sudo in build script for gitlab ci?

When I would like to do something that requiers sudo privelegies, the build process stucks and when ps aux for that command, it hanging in the list but doing nothing.
E.g.:
in the buildscript:
# stop nginx
echo "INFO: stopping nginx. pid [$(cat /opt/nginx/logs/nginx.pid)]"
sudo kill $(cat /opt/nginx/logs/nginx.pid)

in the gitlab ci output console:
INFO: stopping nginx. pid [2741]

kill $(cat /opt/nginx/logs/nginx.pid) # with a spinning wheel

in the bash:
> ps aux | grep nginx

root      6698  0.0  0.1  37628  1264 ?        Ss   19:25   0:00 nginx: master process /opt/nginx/sbin/nginx
nobody    6700  0.3  0.3  41776  3832 ?        S    19:25   0:00 nginx: worker process
kai   7015  0.0  0.0   4176   580 pts/0    S+   19:27   0:00 sh -c sudo kill $(cat /opt/nginx/logs/nginx.pid)
kai   7039  0.0  0.0   7828   844 pts/2    S+   19:27   0:00 grep nginx

So:

not the sudo kill $(cat /opt/nginx/logs/nginx.pid) is going to execute, but sh -c sudo kill $(cat /opt/nginx/logs/nginx.pid)
it is hanging up, without response (sounds for me like it asks for a password interactively)

[Assistant]
There are a couple of ways to resolve this.
Grant sudo permissions
You can grant sudo permissions to the gitlab-runner user as this is who is executing the build script.
$ sudo usermod -a -G sudo gitlab-runner

You now have to remove the password restriction for sudo for the gitlab-runner user.
Start the sudo editor with
$ sudo visudo

Now add the following to the bottom of the file
gitlab-runner ALL=(ALL) NOPASSWD: ALL

Do not do this for gitlab runners that can be executed by untrusted users.

SSH Runner
You can configure the gitlab-ci-runner to connect to a remote host using SSH. You configure this to use a user remotely that has sudo permissions, and perform the build using that user. The remote host can be the same machine that the gitlab runner is executing on, or it can be another host.
This build user account will still need to have sudo and passwordless permissions. Follow the instruction below, except replace gitlab-runner with the build user.


[System] You are a helpful assistant.

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

[Assistant]
Turn off move detection. This can be used to override configuration
settings. It is the same as --color-moved=no .


[System] You are a helpful assistant.

[User]
How to change the project owner in GitLab

How can I change the project owner in GitLab?
There are options in project settings, but in the "transfer" field, it does not recognize any username or anything. Is it possible to change the owner-permissions and root-privileges?

[Assistant]
TL;DR
Move your project to a new group where both you and the other user are owners, then the other user must transfer it to his own namespace.
Background
The other answers obviously do not work to transfer a project to a different user, although the comments section of one is enough for someone to figure it out. Also there is this issue on GitLab itself that provides some insights.
My Situation
I installed and now administer a few instances of GitLab for a few small developer teams as well as one for my personal projects. Resultingly, I have run into numerous questions about this. I keep coming back to this question only to realize that it was never actually answered correctly.
The Namespace Problem
The issue that you face when doing this is that there can only be one owner of a project, but to transfer a project you have to own the namespace that you are transferring it to. To my knowledge there is no other way to move a project. For completeness, I'll add that the namespace here is, e.g., "gitlab.com/my-user-name/..." or "gitlab.com/my-group-name/...".

Solution
Because one user cannot "own" another namespace (not even admins), the only option to set up a scenario where two users own the same namespace is with a group. Perform the following steps to accomplish this.

Create a new group.
Add the user that you want to transfer your project to as an owner member of that group.
Transfer your project to that group (a namespace you manage because you are an owner).
Login as the other user, then transfer the group project to the "other user" namespace.

At this point you will be left as a master in the project. You can now remove yourself from the project entirely if desired.


[System] You are a helpful assistant.

[User]
How to run GitHub Actions workflow only if the pushed files are in a specific folder

I have a folder structure that looks something like this.
- folder1
  - file1
  - *other files*
- folder2
  - file1
  - *other files*
- .gitignore
- package.json
- *other files*

I want to run my GitHub Actions workflow on push, only if any of the changed/pushed files are located in the folder1 directory/folder.

[Assistant]
The normal syntax involves a path filter
on:
  push:
    paths:
      - folder1/**

If that is not enough, you also have the GitHub Action Path Filter.


[System] You are a helpful assistant.

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

[Assistant]
Specifies the radius of history context in days to show in gitk for the selected commit, when the Show History
Context menu item is invoked from git gui blame . If this
variable is set to zero, the whole history is shown.


[System] You are a helpful assistant.

[User]
Meaning of "Allowed to push" and "Allowed to merge" in Gitlab

What's the meaning of "Allowed to push" and "Allowed to merge" in Gitlab protected branches

[Assistant]
Quoting Gitlab Documentation here

Using the "Allowed to push" and "Allowed to merge" settings, you can control the actions that different roles can perform with the protected branch. For example, you could set "Allowed to push" to "No one", and "Allowed to merge" to "Developers + Masters", to require everyone to submit a merge request for changes going into the protected branch

Allowed to push allows the set of people to directly fast-forward commit and non-force push to a particular branch, ideally for protected branches it should be allowed only for Maintainers.
Allowed to merge allows the set of people to merge/pull request into a branch, which for Protected branches like master, should ideally be only for Maintainers again.


[System] You are a helpful assistant.

[User]
TeamCity gitlab integration [closed]

Closed. This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

 We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.

Closed 6 years ago.

                        Improve this question

AFAIK there are not official TeamCity and Gitlab integration plugins, but is there any unofficial project doing this? I need to dynamically build merge requests created on Gitlab on TeamCity and provide feedback of the build status on merge request section.
Anybody have achieved this? Is there any alternative using other CI server?

[Assistant]
Have you checked out Team Citys rather extensive REST API?https://confluence.jetbrains.com/display/TCD10/REST+API
Maybe you can find what you're looking for there?


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-fast-import

[Assistant] Backend for fast Git data importers


[System] You are a helpful assistant.

[User] gitrevisions - Specifying revisions and ranges for Git  <rev>^! , e.g. HEAD^!

[Assistant]
A suffix ^ followed by an exclamation mark is the same
as giving commit <rev> and all its parents prefixed with ^ to exclude them (and their ancestors).


[System] You are a helpful assistant.

[User]
Create comment on pull request

GitHub's comment API seems to allow you to create comments on a pull request, but only if you supply a specific line number in the diff to comment on.  Is there a way to create a comment on the pull request as a whole, the equivalent of typing at the bottom of the pull request screen in GitHub's web interface?

[Assistant]
Yes, it is possible. The section of the API docs you are referencing relates to line comments (comments on specific lines of the commits in the pull req), and the docs say:

Pull Request Review Comments are comments on a portion of the unified diff. These are separate from Commit Comments (which are applied directly to a commit, outside of the Pull Request view), and Issue Comments (which do not reference a portion of the unified diff).

What you need are those Issue comments, which are explained at the top of this page:

The Pull Request API allows you to list, view, edit, create, and even merge pull requests. Comments on pull requests can be managed via the Issue Comments API.

So, in order to create a Pull Request comment, you actually need to create an Issue comment (since a pull request creates an issue to manage it). The page for Issue comments confirms this:

The Issue Comments API supports listing, viewing, editing, and creating comments on issues and pull requests.

So, the request you need to make is:
POST /repos/:owner/:repo/issues/:number/comments

How do you know which issue comment URL to POST to? Well, if you look at the response for getting a single pull request, you will see that it contains an attribute called _links, and that this attribute has a nested comments attribute. This is the URL which you should use for reading and creating pull request comments, the same one as to be used in the POST request above.


[System] You are a helpful assistant.

[User]
Bitbucket activity graph

I would like to know if there is a solution in Bitbucket similar to Github's graphs. For example, here are the ones for Node.js:
Contributions graph

Commits graph

I've done some research and I haven't found anything similar. Does anybody know if this kind of visualisation exists in a hidden place in Bitbucket? Or is there some 3rd party service which provides these kinds of graphs of a git repository?

[Assistant]
Take a look at Awesome Graphs for Bitbucket add-on
From http://blog.bitbucket.org/2015/06/10/atlassian-connect-for-bitbucket-a-new-way-to-extend-your-workflow-in-the-cloud

If you are currently a user of Bitbucket and want to take a sneak peak, click on your avatar, select “Manage Account”, and simply install these new add-ons by selecting “Find new add-ons” from the left menu.

Here is the add-on's release notes page: https://docs.stiltsoft.com/awesome-graphs/cloud/release-notes-cloud


[System] You are a helpful assistant.

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

[Assistant]
DISCUSSION A stash entry is represented as a commit whose tree records the state
of the working directory, and its first parent is the commit at HEAD when the entry was created.  The tree of the second parent records the
state of the index when the entry is made, and it is made a child of
the HEAD commit.  The ancestry graph looks like this: .----W
      /    /
-----H----I where H is the HEAD commit, I is a commit that records the state
of the index, and W is a commit that records the state of the working
tree.


[System] You are a helpful assistant.

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

[Assistant] Manage set of tracked repositories


[System] You are a helpful assistant.

[User]
SSH Agent Forwarding not working

I'm having an hard time trying to configure Capistrano 3.1 to deploy an app hosted on Github.
I'm following Capistrano Documentation and I have successfully completed the first step (SSH keys from workstation to servers) and on the second one (From our servers to the repository host) I'm able to successfully run ssh -A [email protected] 'git ls-remote [email protected]:my_user/my_repo.git':
18f38afz261df35d462f7f4e2ca847d22f148a06    HEAD
18f38afz261df35d462f7f4e2ca847d22f148a06    refs/heads/master

however, ssh [email protected] 'git ls-remote [email protected]:my_user/my_repo.git' fails:
Permission denied (publickey).

Capistrano docs suggests

If you get the error "host key verification failed." log in into your server and run as the deploy user the command ssh [email protected] to add github.com to the list of known hosts.

SO, I tried so but I get
ssh [email protected]
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).

And I'm basically not able to successfully access the Github repo.
SSH documentation states:

-A      Enables forwarding of the authentication agent connection.  This
         can also be specified on a per-host basis in a configuration
         file.

How can I  specified on a per-host basis in a configuration file?
My local machine runs Mac OSX Mavericks.
The VPS runs Ubuntu 12.04
Thanks.

[Assistant]
Do you have your ssh key added to the list of agent identites ?
You can check with ssh-add -L , you should see the key your are using to connect to github :
$ ssh-add -L
ssh-rsa AAAAB3N.....0VmSiRvTzBrbU0ww== /Users/youruser/.ssh/id_rsa

If you don't see the ssh key you use for github or a message like

The agent has no identities.

Then you should add your key with :
ssh-add ~/.ssh/id_rsa

(replace with the path to the key you use for github)
See the ssh-add doc for more info


[System] You are a helpful assistant.

[User]
How to fix "Filename too long error" during git clone
I am trying to take a git clone from a particular branch of my bitbucket repository using the below command:
git clone <url> --branch <branchname>.
However, I am getting the below error while taking the clone:

error:unable to create file foldername/nodemodules/......: Filename
  too long.

I tried resolving this by running the below command in my git cmd
git config --system core.longpaths true.
But I am getting:

error: could not lock config file c://.gitconfig: Permission denied
  error: could not lock config file c://.gitconfig: Invalid argument.

How do I solve these two errors?

[Assistant]
Start Git Bash as Administrator
Run command git config --system core.longpaths true

Another way (only for this clone):
git clone -c core.longpaths=true <repo-url>


[System] You are a helpful assistant.

[User]
Search filenames with GitLab API

I'm using the GitLab API (http://doc.gitlab.com/ce/api/) to try to search for a specific file. I can successfully access a specific repository, but I was hoping to provide some text and retrieve any files that match the filename. If not that, then to at least get the full file structure of everything within the repository and do the search myself. Is this possible?

[Assistant]
http://doc.gitlab.com/ce/api/repositories.html
I didnt skim through the full API docs, but a quick hack would be to list down the trees, you will get Gitlab ObjectifiedHash, run a loop and inside the loop put a condition saying if the type is a 'tree', then send its respective id again to fetch its tree and so on recursively and if its a blob, just save the name.
This way you get all the files/folder name. This is a bad way of doing it since you will do quite a few api calls. Read through the API docs fully.
I know this post is old, just answered anyway. Hope it helped


[System] You are a helpful assistant.

[User] git-checkout - Switch branches or restore working tree files  --overlay  --no-overlay

[Assistant]
In the default overlay mode, git checkout never
removes files from the index or the working tree.  When
specifying --no-overlay , files that appear in the index and
working tree, but not in <tree-ish> are removed, to make them
match <tree-ish> exactly.


[System] You are a helpful assistant.

[User]
How can I view the Git history in Visual Studio Code?
I can execute various Git commands from Visual Studio Code, however I couldn't find a way to visualize the history.

[Assistant]
You won't need a plugin to see commit history with Visual Studio Code 1.44 or more.

Timeline view
This is a unified view for visualizing time-series events (for example, Git commits, file saves, test runs, etc.) for a file. The Timeline view automatically updates showing the timeline for the currently active editor, by default. You can control this default behavior by toggling the eye icon in the view toolbar. Also, similar to other views, the Timeline view supports find or filter as you type.
The Timeline view is collapsed by default at the bottom of the File Explorer. Selecting the Timeline sash will expand the Timeline view.

[...]
Here is the Timeline view in action:


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  --ws-error-highlight=<kind>

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


[System] You are a helpful assistant.

[User] git-branch - List, create, or delete branches  -u <upstream>  --set-upstream-to=<upstream>

[Assistant]
Set up <branchname>'s tracking information so <upstream> is
considered <branchname>'s upstream branch. If no <branchname>
is specified, then it defaults to the current branch.


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  splitIndex.maxPercentChange

[Assistant]
When the split index feature is used, this specifies the
percent of entries the split index can contain compared to the
total number of entries in both the split index and the shared
index before a new shared index is written.
The value should be between 0 and 100. If the value is 0, then
a new shared index is always written; if it is 100, a new
shared index is never written.
By default, the value is 20, so a new shared index is written
if the number of entries in the split index would be greater
than 20 percent of the total number of entries.
See git-update-index .


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  http.saveCookies

[Assistant]
If set, store cookies received during requests to the file specified by
http.cookieFile. Has no effect if http.cookieFile is unset.


[System] You are a helpful assistant.

[User]
Ignore modified (but not committed) files in git?
Can I tell git to ignore files that are modified (deleted) but should not be committed?
The situation is that I have a subdirectory in the repo which contains stuff I'm not interested in at all, so I deleted it to prevent it showing up in auto-completions and the like (in the IDE).
But now, if I add that folder to .gitignore, simply nothing changes, all the stuff is shown as deleted by git status.
Is there a way to make git ignore it either way?
(Alternatively, as I'm using git-svn, could I commit the changes to the local git and ensure they are not passed on to the svn repo?)

[Assistant]
check out the git-update-index man page and the --assume-unchanged bit and related.
when I have your problem I do this
git update-index --assume-unchanged dir-im-removing/

or a specific file
git update-index --assume-unchanged config/database.yml


[System] You are a helpful assistant.

[User]
Visualize branches on GitHub
In TortoiseGit, gitk or on BitBucket, it is common to have a visualization of the project history with all the branches, like this:

However, GutHub's commit history seems to be flat, at least I couldn't find a way to display this kind of graph. Can the GitHub's web UI somehow visualize branches like other Git clients commonly can?

[Assistant]
You can see a graph, but without commit messages in Insights => Network section (commit messages with authors are shown on hover).
Note: this works for public repos or GitHub Enterprise only!
Example: https://github.com/google/orbit/network


[System] You are a helpful assistant.

[User]
How to add a local repo and treat it as a remote repo
I'm trying to make a local repo act as a remote with the name bak for another local repo on my PC, using the following:
git remote add /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git bak

which gives this error:
fatal: '/home/sas/dev/apps/smx/repo/bak/ontologybackend/.git' is not a valid remote name

I'm trying to sync two local repos, with one configured as a remote named bak for the other, and then issuing git pull bak.
What is the best way to do it?

[Assistant]
You have your arguments to the remote add command reversed:
git remote add <NAME> <PATH>

So:
git remote add bak /home/sas/dev/apps/smx/repo/bak/ontologybackend/.git

See git remote --help for more information.


[System] You are a helpful assistant.

[User]
.gitignore ignore all files then recursively allow *.foo
There's already several questions similar to this, but none of the answers work for me.
I want to ignore everything in the folders below my repository except files with *.foo
(If anyone is wondering how this can be justified - I'm actually making a git repository for all my "Logic" projects - music software on the mac - but I only want to store the actual project files *.logic)
I'm going to spell it out, so we're all on the same plate.
Here's what I do, starting from scratch:
Setup:
mkdir temp
cd temp
mkdir testdir
cd testdir
touch include.foo
touch dontinclude.bad
cd..
git init
touch .gitignore

Paste this in to .gitignore
# Ignore all
/*

# But not these files...
!.gitignore
!*.foo

git status
And the only untracked file is .gitignore
if I typed 'git add .' - no change, only .gitignore is seen and my 2 files are ignored.
Why doesn't this work and how can you change the procedure above to make it work?
Here's the extremely similar question where I got the .gitignore file from.
I'm using git --version 1.7.7 (also tried 1.7.3) - .gitignore to ignore all files, then recursively allows files of a certain type

[Assistant]
Your problem is that the /* pattern at the beginning is matching all files and directories at the top level - including testdir, so everything inside testdir is ignored.
This is what you want:
# Ignore everything
*
# Don't ignore directories, so we can recurse into them
!*/
# Don't ignore .gitignore and *.foo files
!.gitignore
!*.foo

When you do a git add . with this config, you should find you have only .gitignore and *.foo files listed as changes to be committed.


[System] You are a helpful assistant.

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

[Assistant] Include additional statistics at the end of blame output.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  --work-tree=<path>

[Assistant]
Set the path to the working tree. It can be an absolute path
or a path relative to the current working directory.
This can also be controlled by setting the GIT_WORK_TREE
environment variable and the core.worktree configuration
variable (see core.worktree in git-config for a
more detailed discussion).


[System] You are a helpful assistant.

[User] git-diff-index - Compare a tree to the working tree or index  -X[<param1,param2,…>]  --dirstat[=<param1,param2,…>]

[Assistant]
Output the distribution of relative amount of changes for each
sub-directory. The behavior of --dirstat can be customized by
passing it a comma separated list of parameters.
The defaults are controlled by the diff.dirstat configuration
variable (see git-config ).
The following parameters are available: changes Compute the dirstat numbers by counting the lines that have been
removed from the source, or added to the destination. This ignores
the amount of pure code movements within a file.  In other words,
rearranging lines in a file is not counted as much as other changes.
This is the default behavior when no parameter is given. lines Compute the dirstat numbers by doing the regular line-based diff
analysis, and summing the removed/added line counts. (For binary
files, count 64-byte chunks instead, since binary files have no
natural concept of lines). This is a more expensive --dirstat behavior than the changes behavior, but it does count rearranged
lines within a file as much as other changes. The resulting output
is consistent with what you get from the other --*stat options. files Compute the dirstat numbers by counting the number of files changed.
Each changed file counts equally in the dirstat analysis. This is
the computationally cheapest --dirstat behavior, since it does
not have to look at the file contents at all. cumulative Count changes in a child directory for the parent directory as well.
Note that when using cumulative , the sum of the percentages
reported may exceed 100%. The default (non-cumulative) behavior can
be specified with the noncumulative parameter. <limit> An integer parameter specifies a cut-off percent (3% by default).
Directories contributing less than this percentage of the changes
are not shown in the output. Example: The following will count changed files, while ignoring
directories with less than 10% of the total amount of changed files,
and accumulating child directory counts in the parent directories: --dirstat=files,10,cumulative .


[System] You are a helpful assistant.

[User] git - the stupid content tracker  <old|new>-mode

[Assistant]
are the octal representation of the file modes. The file parameters can point at the user’s working file
(e.g. new-file in "git-diff-files"), /dev/null (e.g. old-file when a new file is added), or a temporary file (e.g. old-file in the
index). GIT_EXTERNAL_DIFF should not worry about unlinking the
temporary file — it is removed when GIT_EXTERNAL_DIFF exits. For a path that is unmerged, GIT_EXTERNAL_DIFF is called with 1
parameter, <path>. For each path GIT_EXTERNAL_DIFF is called, two environment variables, GIT_DIFF_PATH_COUNTER and GIT_DIFF_PATH_TOTAL are set.


[System] You are a helpful assistant.

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

[Assistant]
The new name for an existing branch. The same restrictions as for
<branchname> apply.


[System] You are a helpful assistant.

[User]
Why is Git better than Subversion?
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.

I've been using Subversion for a few years and after using SourceSafe, I just love Subversion.  Combined with TortoiseSVN, I can't really imagine how it could be any better.
Yet there's a growing number of developers claiming that Subversion has problems and that we should be moving to the new breed of distributed version control systems, such as Git.
How does Git improve upon Subversion?

[Assistant]
Git is not better than Subversion. But is also not worse. It's different.
The key difference is that it is decentralized. Imagine you are a developer on the road, you develop on your laptop and you want to have source control so that you can go back 3 hours.
With Subversion, you have a Problem: The SVN Repository may be in a location you can't reach (in your company, and you don't have internet at the moment), you cannot commit. If you want to make a copy of your code, you have to literally copy/paste it.
With Git, you do not have this problem. Your local copy is a repository, and you can commit to it and get all benefits of source control. When you regain connectivity to the main repository, you can commit against it.
This looks good at first, but just keep in mind the added complexity to this approach.
Git seems to be the "new, shiny, cool" thing. It's by no means bad (there is a reason Linus wrote it for the Linux Kernel development after all), but I feel that many people jump on the "Distributed Source Control" train just because it's new and is written by Linus Torvalds, without actually knowing why/if it's better.
Subversion has Problems, but so does Git, Mercurial, CVS, TFS or whatever.
Edit: So this answer is now a year old and still generates many upvotes, so I thought I'll add some more explanations. In the last year since writing this, Git has gained a lot of momentum and support, particularly since sites like GitHub really took off. I'm using both Git and Subversion nowadays and I'd like to share some personal insight.
First of all, Git can be really confusing at first when working decentralized. What is a remote? and How to properly set up the initial repository? are two questions that come up at the beginning, especially compared to SVN's simple "svnadmin create", Git's "git init" can take the parameters --bare and --shared which seems to be the "proper" way to set up a centralized repository. There are reasons for this, but it adds complexity. The documentation of the "checkout" command is very confusing to people changing over - the "proper" way seems to be "git clone", while "git checkout" seems to switch branches.
Git REALLY shines when you are decentralized. I have a server at home and a Laptop on the road, and SVN simply doesn't work well here. With SVN, I can't have local source control if I'm not connected to the repository (Yes, I know about SVK or about ways to copy the repo). With Git, that's the default mode anyway. It's an extra command though (git commit commits locally, whereas git push origin master pushes the master branch to the remote named "origin").
As said above: Git adds complexity. Two modes of creating repositories, checkout vs. clone, commit vs. push... You have to know which commands work locally and which work with "the server" (I'm assuming most people still like a central "master-repository").
Also, the tooling is still insufficient, at least on Windows. Yes, there is a Visual Studio AddIn, but I still use git bash with msysgit.
SVN has the advantage that it's MUCH simpler to learn: There is your repository, all changes to towards it, if you know how to create, commit and checkout and you're ready to go and can pickup stuff like branching, update etc. later on.
Git has the advantage that it's MUCH better suited if some developers are not always connected to the master repository. Also, it's much faster than SVN. And from what I hear, branching and merging support is a lot better (which is to be expected, as these are the core reasons it was written).
This also explains why it gains so much buzz on the Internet, as Git is perfectly suited for Open Source projects: Just Fork it, commit your changes to your own Fork, and then ask the original project maintainer to pull your changes. With Git, this just works. Really, try it on Github, it's magic.
What I also see are Git-SVN Bridges: The central repository is a Subversion repo, but developers locally work with Git and the bridge then pushes their changes to SVN.
But even with this lengthy addition, I still stand by my core message: Git is not better or worse, it's just different. If you have the need for "Offline Source Control" and the willingness to spend some extra time learning it, it's fantastic. But if you have a strictly centralized Source Control and/or are struggling to introduce Source Control in the first place because your co-workers are not interested, then the simplicity and excellent tooling (at least on Windows) of SVN shine.


[System] You are a helpful assistant.

[User]
How to git clone with username and password in gitlab?

I am using gitlab . I want to write a .bat file which contains all the steps so that I can automate all the process , which are as follows:

open cmd.exe /k
git init
git clone https://username:[email protected]/board.git  ////// not working
git status

The 3rd point that is git clone https.... is not working in gitBash anymore. I tried using git clone SSH ... and it  is working which asked for the passphrase and after logging in it was about to clone the repo. As I want to automate the process by providing the login credentials by-default , how can it be achieved using SSH. Thank you.

[Assistant]
Adding username before gitlab worked for me. It will ask password afterwards.
git clone https://[email protected]/project.git


[System] You are a helpful assistant.

[User]
Managing many git repositories
Setting up a project is easy in git and so I can have separate repository even for small script. Now the problem is how to manage them.
I work in multiple places with these repositories. When I have done changes to some repository, I want to be able to update the repositories in other places.
So I have a directory with many repositories in it.

How can I fetch all of them?
How can I check whether any of them have uncommitted changes?
How can I check whether any of them have changes to merge?

And it would be nice to be able to do these with one command.
The output needs to be silent enough to actually notice the things to do.

[Assistant]
I highly recommend the multiple repositories tool mr. I used to use a custom shell script as recommended by others for some time, but using mr has the following benefits for me:

It's generic: A conjunction of various version control systems can be used, not only git (e.g. Mercurial, SVN, etc.).
It's fast: mr can execute multiple jobs in parallel. I use a number of git/mercurial repositories and sync them several times a day. Mr tremendously speeds up this process.
It's easy and quick to manage the list of repository checkouts. Just use 'mr register' rather than modifying the list of projects in your custom script.

Regarding to your question about silent output: The level of verbosity can be modified using the command line switch -q. I prefer the default output which appears to nicely unify the output in a short and clear summary.
I use the following alias for the mr command to ensure that mr always picks up my default project list stored in $HOME, and uses 5 parallel threads:
alias mr='mr -d ~/ -j 5 '


[System] You are a helpful assistant.

[User]
Can I edit two files then make one commit using GitHub Web-based editor?
GitHub has the nice feature of Web-based file editing. However, it seems that after editing one file I have to commit the changes for this file before continuing. Is there a way I can edit two or more files then make one commit for all the changes of them?
I think this would be better since too many unnecessary commits are annoying.

[Assistant]
There is a web-based workaround:

Create a temporary branch, switch to it;
Edit multiple files, commit each file separately;
Make pull request;
Under Merge pull request button, choose Squash and merge (if the repo allows it), then confirm merge;
Delete temporary branch.

I use this method on a PC which I don't want to install git on.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --grep=<pattern>

[Assistant]
Limit the commits output to ones with a log message that
matches the specified pattern (regular expression).  With
more than one --grep=<pattern> , commits whose message
matches any of the given patterns are chosen (but see --all-match ). When --notes is in effect, the message from the notes is
matched as if it were part of the log message.


[System] You are a helpful assistant.

[User]
What exactly does git rebase --skip do?
I just did a git pull --rebase origin master and there was a conflict.
Firstly, this conflict was in a file that I hadnt touched, and was about 10 commits back. Why does this happen?
I then accidently typed git rebase --skip, and it 'skipped that patch'.
Worried that I had skipped a commit, I checked out a new version of the master branch and did a diff between the branch that I did the rebase on, and the new master branch.  The only changes that show up in the diff are the latest commit, and looking at the log, the patch that was 'skipped', shows up in the commit history.
Can anyone explain what is going on here?

[Assistant]
It does what it says, it skips a commit. If you run rebase --abort at a later conflict during the same rebase, the skipped commit will be reverted too of course.
If your change already existed upstream, Git will not be able to apply your commit (but usually should skip it automatically, if the patch is exactly the same). Your own commit will be skipped, but the change will still exist in current HEAD, because it was already applied upstream.
You should really make sure you did not remove an important change of yours ;) (use the reflog to go back to the state before the rebase)


[System] You are a helpful assistant.

[User]
Switch branch and ignore any changes without committing
I was working on a git branch and was ready to commit my changes, so I made a commit with a useful commit message. I then absentmindedly made minor changes to the code that are not worth keeping. I now want to change branches, but git gives me,

error: You have local changes to "X"; cannot switch branches.

Can I change branches without committing? If so, how can I set this up? If not, how do I get out of this problem? I want to ignore the minor changes without committing and just change branches.

[Assistant]
You need a clean state to change branches. The branch checkout will only be allowed if it does not affect the 'dirty files' (as Charles Bailey remarks in the comments).
Otherwise, you should either:

stash your current change or
reset --hard HEAD  (if you do not mind losing those minor changes) or
checkout -f (When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes. )

Or, more recently:

With Git 2.23 (August 2019) and the new command git switch:
git switch -f <branch-name>
(-f is short for --force, which is an alias for --discard-changes)

Proceed even if the index or the working tree differs from HEAD.
Both the index and working tree are restored to match the switching target.

This differs from git switch -m <branch-name>, which triggers a three-way merge between the current branch, your working tree contents, and the new branch: you won't lose your work in progress that way.


[System] You are a helpful assistant.

[User] git-diff - Show changes between commits, commit and working tree, etc  --find-object=<object-id>

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


[System] You are a helpful assistant.

[User]
git checkout: what does this weird output mean?
When I checkout, I get:
me@localhost# git checkout master
D    deps/example
M    deps/example2
Switched to branch "master"

The man page doesn't mention this cryptic output. What does it mean?

[Assistant]
That's the output of git status; git is showing you that after checking out master there are still uncommited changes to your working copy (one modified file and one deleted file).
Check man git-status:
M = modified
A = added
D = deleted
R = renamed
C = copied
U = updated but unmerged


[System] You are a helpful assistant.

[User]
How can I remove all files in my git repo and update/push from my local git repo?

Is it possible to remove all files in a repository and update it with only the files I have in my local machine? The reason is that, there are certain files that is not necessary in my github and so I want to remove those files. Instead of removing the files one by one, I wanted to see if its possible to just remove all files in my git repo and update/push with only the files in my local machine. Hope its clear. Thanks.

[Assistant]
You could do it like this:
cd /tmp
git clone /your/local/rep  # make a temp copy
cd rep
git rm -r *                # delete everything
cp -r /your/local/rep/* .  # get only the files you want
git add *                  # add them again
git status                 # everything but those copied will be removed
git commit -a -m 'deleting stuff'
cd /your/local/rep
git pull /tmp/rep          # now everything else has been removed

There's probably a oneliner for that…


[System] You are a helpful assistant.

[User] git - the stupid content tracker  -p  --paginate

[Assistant]
Pipe all output into less (or if set, $PAGER) if standard
output is a terminal.  This overrides the pager.<cmd> configuration options (see the "Configuration Mechanism" section
below).


[System] You are a helpful assistant.

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

[Assistant]
You can set this to link , in which case a hardlink followed by
a delete of the source are used to make sure that object creation
will not overwrite existing objects. On some file system/operating system combinations, this is unreliable.
Set this config setting to rename there; however, this will remove the
check that makes sure that existing object files will not get overwritten.


[System] You are a helpful assistant.

[User] git-reset - Reset current HEAD to the specified state  Undo commits permanently

[Assistant]
$ git commit ...
$ git reset --hard HEAD~3 (1) The last three commits ( HEAD , HEAD^ , and HEAD~2 ) were bad
and you do not want to ever see them again.  Do not do this if
you have already given these commits to somebody else.  (See the
"RECOVERING FROM UPSTREAM REBASE" section in git-rebase for the implications of doing so.)


[System] You are a helpful assistant.

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

[Assistant] Branch to switch to.


[System] You are a helpful assistant.

[User] gitglossary - A Git Glossary  cache

[Assistant] Obsolete for: index .


[System] You are a helpful assistant.

[User]
Can TortoiseMerge be used as a difftool with Windows Git Bash?
I'm just starting to work with Git.  I would like to use TortoiseMerge as the difftool and mergetool.
In my $HOME/.gitconfig I have the following sections. I've removed the user and color sections for this question.
[merge]
    tool = tortoisemerge
[mergetool "tortoisemerge"]
    cmd = \"TortoiseMerge.exe\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"
[diff]
    tool = tortoisemerge
[difftool "tortoisemerge"]
    cmd = \"TortoiseMerge.exe\" -base:\"$BASE\" -mine:\"$LOCAL\" -theirs:\"$REMOTE\" -merged:\"$MERGED\"

If I type tortoisemerge at the Git Bash prompt it loads. It is known to be on the path. But if I type the command I get the following error.
Rich:mygittest (master *)
$ git difftool
error: 'tortoisemerge' can only be used to resolve merges
merge tool candidates: kompare emerge vimdiff
No known merge resolution program available.
external diff died, stopping at readme.txt.
Rich:mygittest (master *)
$

What am I not understanding to make this work?
Tortoisemerge is installed with TortoiseSVN.

[Assistant]
The following settings work fine for me. However, I am using TortoiseGit not TortoiseSVN. Notice the difference in the parameters for diff.
[diff]
  tool = tortoisediff
[difftool]
  prompt = false
[merge]
  tool = tortoisemerge
[mergetool]
  prompt = false
  keepBackup = false
[difftool "tortoisediff"]
  cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -mine "$REMOTE" -base "$LOCAL"
[mergetool "tortoisemerge"]
  cmd = \""c:/Program Files/TortoiseGIT/bin/TortoiseGitMerge.exe"\" -base "$BASE" -theirs "$REMOTE" -mine "$LOCAL" -merged "$MERGED"


[System] You are a helpful assistant.

[User] git-show - Show various types of objects  allow-indentation-change

[Assistant]
Initially ignore any whitespace in the move detection, then
group the moved code blocks only into a block if the change in
whitespace is the same per line. This is incompatible with the
other modes.


[System] You are a helpful assistant.

[User]
A pretty and feature rich Git GUI for Linux [closed]
Closed. This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

 We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

                        Improve this question

I was checking out for a rich GUI for Git on Linux. As of late, I have started using it a lot and find that even though command-line is very useful, I would still want a GUI at my disposal since I am not still very much aware with the advanced features.
I came across this question on Stack Overflow before, but I still have to ask this question again, as that question doesn't have my answer

I have used git-cola and gitk, but they look half-baked and gitk looks like I am working on some other desktop environment. All the features I require in gitGUI is not in either of them.

I tried giggle, but it is more useful for watching diffs

I tried QGit, but it is not fully complete.

Now let me tell how I want a foo-Git-GUI to look like:

You can have a look at Bzr Explorer. It is highly usable and has many more features than many of the above mentioned GUIs

Is there any Git GUI which looks like the above example I posted above?

[Assistant]
I find myself using mainly gitg in combination with the command line for more complicated tasks.
Source repository: http://git.gnome.org/browse/gitg.
Recently, a new version 0.3.2 has been released, which is a rewrite using Vala. It's not yet feature-complete compared to the old 0.2 series, but the refactor is expected to speed up future development.
Also, there are normally PPAS on Launchpad which contain a more up-to-date version than the standard repository.


[System] You are a helpful assistant.

[User] git-for-each-ref - Output information on each ref  --shell  --perl  --python  --tcl

[Assistant]
If given, strings that substitute %(fieldname) placeholders are quoted as string literals suitable for
the specified host language.  This is meant to produce
a scriptlet that can directly be `eval`ed.


[System] You are a helpful assistant.

[User]
Explain which gitignore rule is ignoring my file
Is there any way to see why some file is getting ignored by git (i.e. which rule in a .gitignore file is causing the file to be ignored)?
Imagine I have this (or a much more complex scenario, with hundreds of folders and tens of .gitignore files:
/
-.gitignore
-folder/
    -.gitignore
    -subfolder/
              -.gitignore
              -file.txt

If I run git add folder/subfolder/file.txt git may complain of it being ignored:
The following paths are ignored by one of your .gitignore files:
folder/subfolder/file.txt
Use -f if you really want to add them.

Is there any way to know which of all the possible .gitignore have a rule to ignore this file, and also show the rule? Like:
The following paths are ignored by your folder/.gitignore file (line 12: *.txt)
folder/subfolder/file.txt
Use -f if you really want to add them.

Or just:
$ git why-is-ignored folder/subfolder/file.txt
folder/.gitignore:12:*.txt

[Assistant]
git check-ignore -v filename

See the man page for more details.
Original answer follows:
git does not currently provide anything like this.  But after seeing your question I did some googling and found that back in 2009 this feature was requested and partially implemented.  After reading the thread, I realised it would not be too much work to do it properly, so I have started work on a patch and hope to have it finished in the next day or two.  I will update this answer when it is ready.
UPDATE: Wow, that was a lot harder than I expected.  The innards of git's exclude handling are quite cryptic.  Anyway, here's an almost finished series of commits which apply to today's upstream master branch.  The test suite is 99% complete, but I haven't finished handling of the --stdin option yet.  Hopefully I'll manage that this weekend, and then submit my patches to the git mailing list.
In the meantime, I'd definitely welcome testing from anyone who's able to do so - just clone from my git fork, check out the check-ignore branch, and compile it as normal.
UPDATE 2: It's done! Latest version is on github as per above, and I have submitted the patch series to the git mailing list for peer review.  Let's see what they think ...
UPDATE 3: After several more months of hacking / patch reviews / discussions / waiting, I'm delighted to be able to say that this feature has now reached git's master branch, and will be available in the next release (1.8.2, expected 8th March 2013).  Here's the check-ignore manual page.  Phew, that was way more work than I expected!
UPDATE 4: If you're interested in the full story about how this answer evolved and the feature came to be implemented, check out episode #32 of the GitMinutes podcast.


[System] You are a helpful assistant.

[User]
How do I squash specific commits on a local branch?
I can find a few answers out there that come close to what I want, but I'm afraid I'm not really experienced enough with Git to exactly understand how to achieve what I want.
Given a local branch with commits A-B-C-D-E-F-G-H-I-J on it, I want to squash some of the commits together so that I end up with, for example, the equivalent of A-BCD-E-FGH-IJ.
Is this possible? The intention is to do this to a local branch, after rebasing, but before merging back into the master branch, in order to create a more concise and informative history.

[Assistant]
You can do this with rebase. Assuming commits A–J are on a local branch branchname built on top of master, then you can do this:
git checkout branchname
git rebase -i master

You'll be presented with an interactive window like this:
pick A Commit message A
pick B Commit message B
pick C Commit message C
pick D Commit message D
pick E Commit message E
...

Interactive rebase provides instructions for your scenario, so you should change "pick" to "squash" for C and D (and the same for G, H and J):
pick A Commit message A
pick B Commit message B
squash C Commit message C
squash D Commit message D
pick E Commit message E

This will squash B, C and D into a single commit, allowing you to change the commit message.
If you're happy to use the commit message of B, you can use "fixup" instead of "squash" and you won't be prompted to update the commit message.

The interactive window is very powerful, and you can reorder commits as much as you want, or even just delete the line (or change the prefix to "drop") and that commit will be removed. For instance, if E fixes a typo that you made in A, you can do this:
pick A Commit message A
fixup E Commit message E
pick B Commit message B
pick C Commit message C
pick D Commit message D

However, when you reorder commits, you run the risk of having to resolve conflicts along the way. You can always use git rebase --abort to return to your original state.


[System] You are a helpful assistant.

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

[Assistant]
When used with the value-pattern argument, treat value-pattern as
an exact string instead of a regular expression. This will restrict
the name/value pairs that are matched to only those where the value
is exactly equal to the value-pattern .


[System] You are a helpful assistant.

[User]
How to rollback the two previous commits?

Consider this scenario:

Developer A does a commit: #n
Dev. B does commit #n+1
Dev. A does commit #n+2
and commit #n+3

and then discovers that in his commit #n+2 he introduced a defect.
How can dev. A rollback his last 2 commits and continue developing on commit #n+1?
Tried git reset --hard HEAD~2*, but it's coming back to dev A's commit #n.

[Assistant]
It should come back to the n+1 commit. You probably have a merge commit in there as well. You can also do a git reset --hard <sha1_of_where_you_want_to_be>

WARNING!! --hard means that any uncommitted changes you currently have
  will be thrown away permanently.


[System] You are a helpful assistant.

[User]
Git confusion - how to revert local changes to latest remote push?
I have a local git repository, but things get wrong and complicated and I simply want to overwrite all the files in my local directory with the latest version of what is on the remote repository. This would be like a clone, but for an already setup local git repository.
For example: if use git pull, then I don't get locally deleted folders back from the remote.
Is it checkout that I must use? But how to tell it to retrieve the files from a remote (and not from the stage) and overwrite all?

[Assistant]
You probably want to use git reset.  Assuming you have done a git fetch recently, the following will discard everything in your local and reset it to the point you specify as the final argument (in this case the current HEAD of the origin/master remote tracking branch):
$ git reset --hard origin/master


[System] You are a helpful assistant.

[User]
How to use Gitlab CI/CD to deploy a meteor project?

As claimed at their website Gitlab can be used to auto deploy projects after some code is pushed into the repository but I am not able to figure out how. There are plenty of ruby tutorials out there but none for meteor or node.
Basically I just need to rebuild an Docker container on my server, after code is pushed into my master branch. Does anyone know how to achieve it? I am totally new to the .gitlab-ci.yml stuff and appreciate help pretty much.

[Assistant]
Brief: I am running a Meteor 1.3.2 app, hosted on Digital Ocean (Ubuntu 14.04) since 4 months. I am using Gitlab v. 8.3.4 running on the same Digital Ocean droplet as the Meteor app. It is a 2 GB / 2 CPUs droplet ($ 20 a month). Using the built in Gitlab CI for CI/CD. This setup has been running successfully till now. (We are currently not using Docker, however this should not matter.)
Our CI/CD strategy:

We check out Master branch on our local laptop. The branch contains the whole Meteor project as shown below:

We use git CLI tool on Windows to connect to our Gitlab server. (for pull, push, etc. similar regular git activities)

Open the checked out project in Atom editor. We have also integrated Atom with Gitlab. This helps in quick git status/pull/push etc. within Atom editor itself. Do regular Meteor work viz. fix bugs etc.
Post testing on local laptop, we then do git push & commit on master. This triggers auto build using Gitlab CI and the results (including build logs) can be seen in Gitlab itself as shown below:

Below image shows all previous build logs:

Please follow below steps:

Install meteor on the DO droplet.
Install Gitlab on DO (using 1-click deploy if possible) or manual installation. Ensure you are installing Gitlab v. 8.3.4 or newer version. I had done a DO one-click deploy on my droplet.
Start the gitlab server & log into gitlab from browser. Open your project and go to project settings -> Runners from left menu

SSH to your DO server & configure a new upstart service on the droplet as root:
vi /etc/init/meteor-service.conf

Sample file:
#upstart service file at /etc/init/meteor-service.conf
description "Meteor.js (NodeJS) application for eaxmple.com:3000"
author "[email protected]"

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on shutdown

# Automatically restart process if crashed
respawn
respawn limit 10 5

script
    export PORT=3000
    # this allows Meteor to figure out correct IP address of visitors
    export HTTP_FORWARDED_COUNT=1
    export MONGO_URL=mongodb://xxxxxx:[email protected]:59672/meteor-db
    export ROOT_URL=http://<droplet_ip>:3000
    exec /home/gitlab-runner/.meteor/packages/meteor-tool/1.1.10/mt-os.linux.x86_64/dev_bundle/bin/node /home/gitlab-runner/erecaho-build/server-alpha-running/bundle/main.js >> /home/gitlab-runner/erecaho-build/server-alpha-running/meteor.log
end script

Install gitlab-ci-multi-runner from here: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/linux-repository.md as per the instructions
Cheatsheet:
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash
sudo apt-get install gitlab-ci-multi-runner
sudo gitlab-ci-multi-runner register

Enter details from step 2
Now the new runner should be green or activate the runner if required
Create .gitlab-ci.yml within the meteor project directory
Sample file:
before_script:
  - echo "======================================"
  - echo "==== START auto full script v0.1 ====="
  - echo "======================================"

types:
  - cleanup
  - build
  - test
  - deploy

job_cleanup:
  type: cleanup
  script:
  - cd /home/gitlab-runner/erecaho-build
  - echo "cleaning up existing bundle folder"
  - echo "cleaning up current server-running folder"
  - rm -fr ./server-alpha-running
  - mkdir ./server-alpha-running
  only:
  - master
  tags:
  - master

job_build:
  type: build
  script:
  - pwd
  - meteor build /home/gitlab-runner/erecaho-build/server-alpha-running --directory --server=http://example.org:3000 --verbose
  only:
  - master
  tags:
  - master

job_test:
  type: test
  script:
  - echo "testing ----"
  - cd /home/gitlab-runner/erecaho-build/server-alpha-running/bundle
  - ls -la main.js
  only:
  - master
  tags:
  - master

job_deploy:
  type: deploy
  script:
  - echo "deploying ----"
  - cd /home/gitlab-runner/erecaho-build/server-alpha-running/bundle/programs/server/ && /home/gitlab-runner/.meteor/packages/meteor-tool/1.1.10/mt-os.linux.x86_64/dev_bundle/bin/npm install
  - cd ../..
  - sudo restart meteor-service
  - sudo status meteor-service
  only:
  - master
  tags:
  - master

Check in above file in gitlab. This should trigger Gitlab CI and after the build process is complete, the new app will be available @ example.net:3000

Note: The app will not be available after checking in .gitlab-ci.yml for the first time, since restart meteor-service will result in service not found. Manually run sudo start meteor-service once on DO SSH console. Post this any new check-in to gitlab master will trigger auto CI/CD and the new version of the app will be available on example.com:3000 after the build is completed successfully.
P.S.: gitlab ci yaml docs can be found at http://doc.gitlab.com/ee/ci/yaml/README.html for your customization and to understand the sample yaml file above.
For docker specific runner, please refer https://gitlab.com/gitlab-org/gitlab-ci-multi-runner


[System] You are a helpful assistant.

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

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


[System] You are a helpful assistant.

[User]
How to remove file from Git history?

Some time ago I added info(files) that must be private. Removing from the project is not problem, but I also need to remove it from git history.
I use Git and Github (private account).
Note: On this thread  something similar is shown, but here is an old file that was added to a feature branch, that branch merged to a development branch and finally merged to master, since this, a lot of changes was done. So it's not the same and what is needed is to change the history, and hide that files for privacy.

[Assistant]
I have found this answer and it helped:
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch path_to_file' HEAD


[System] You are a helpful assistant.

[User]
git ahead/behind info between master and branch?

I have created a branch for testing in my local repo (test-branch) which I pushed to Github.
If I go to my Github account and select this test-branch it shows the info:
This branch is 1 commit ahead and 2 commits behind master

My questions are:

How can I display this info locally (ie: a command that shows this on the terminal, rather than having to open Github to see it)?
I know I can see the diffs between branches using:
git diff master..test-branch

or using Meld (which I prefer):
git difftool master..test-branch

but I was wondering if there's a way to see the ahead and behind commits separately. I.E.: is there a way to show that 1 commit ahead by itself and then those 2 commits behind by themselves?

[Assistant]
Part 1
As an answer on your question 1, here's a trick I found to compare two branches and show how many commits each branch is ahead of the other (a more general answer on your question 1):
For local branches:
git rev-list --left-right --count master...test-branch
For remote branches:
git rev-list --left-right --count origin/master...origin/test-branch
This gives output like the following:
2       1
This output means: "Compared to master, test-branch is 1 commit ahead and 2 commits behind."
You can also compare local branches with remote branches, e.g. origin/master...master to find out how many commits a local branch (here master) is ahead/behind its remote counterpart.
Part 2
To answer the second part of your question, the solution depends on what exactly you want to achieve.
To view commits
In order to have git rev-list return the exact list of commits unique on either side, replace the --count argument with something like --pretty=oneline, making the complete command to execute:
git rev-list --left-right --pretty=oneline master...test-branch

This will generate output like this:
<bba27b56ad7072e281d529d4845e4edf877eb7d7 unique commit 2 on master
<dad0b69ec50ea57b076bfecabf2cc7c8a652bb6f unique commit 1 on master
>4bfad52fbcf0e60d78d06661d5c06b59c98ac8fd unique commit 1 on test-branch

Here every commit sha is preceded by < or > to indicate which branch it can be found on (left or right, here master or test-branch respectively).
To view code
If you want to view a diff of all new commits only found on either branch, you'll need to do this in two steps:

define the most recent common ancestor

$ git merge-base master test-branch
c22faff7468d6d5caef217ac6b82f3ed95e9d902

diff either branch to the commit sha obtained above (short format will usually do)

To show the diff of all commits only found on master
git diff c22faff7..master

To show the diff of all commits only found test-branch
git diff c22faff7..test-branch


[System] You are a helpful assistant.

[User]
Move file and directory into a sub-directory along with commit history
How can I move a directory and files to a sub-directory along with commit history?
For example:

Source directory structure: [project]/x/[files & sub-dirs]
Target directory structure: [project]/x/p/q/[files & sub-dirs]

[Assistant]
To add to bmargulies's comment, the complete sequence is:
mkdir -p x/p/q      # make sure the parent directories exist first
git mv x/* x/p/q    # move folder, with history preserved
git commit -m "changed the foldername x into x/p/q"

Try it first to see a preview of the move:
git mv -n x/* x/p/q

Wolfgang comments:

If you're using bash, you can avoid the issue of trying to move a folder into itself by using an extended glob like so (using the shopt built-in):

shopt -s extglob; git mv !(folder) folder

Captain Man reports in the comments  having to do:
mkdir temp
git mv x/* temp
mkdir -p x/p/q
git mv temp x/p/q
rmdir temp;

Context:

I am on Windows with Cygwin.
  I just realized I did the shopt -s extglob example wrong so my way may not have be necessary, but I typically do use zsh instead of bash, and it didn't have the command shopt -s extglob (though I'm sure there is an alternative), so this approach should work across shells (subbing in your shell's mkdir and rmdir if it's especially foreign)

As an alternative, spanky mentions in the comments the -k option of git mv:

Skip move or rename actions which would lead to an error condition.

git mv -k * target/

That would avoid the "can not move directory into itself" error.


[System] You are a helpful assistant.

[User] git - the stupid content tracker  git-check-attr

[Assistant] Display gitattributes information


[System] You are a helpful assistant.

[User] git-filter-branch - Rewrite branches  --index-filter <command>

[Assistant]
This is the filter for rewriting the index.  It is similar to the
tree filter but does not check out the tree, which makes it much
faster.  Frequently used with git rm --cached
--ignore-unmatch ... , see EXAMPLES below.  For hairy
cases, see git-update-index .


[System] You are a helpful assistant.

[User]
Get github username by id

Using this link I can see that my (tonylampada) id on github is 218821
https://api.github.com/users/tonylampada
How could I do the opposite? Given the user id = 218821, what's the username?

Update
Answering nulltoken here because it's a long story and it won't fit in a comment.
FreedomSponsors is a django application that uses django-social-auth to enable login with Github (and others).
(You should check it out, btw, please see the about page in the blog :-)
Django-social-auth has a configuration flag that allows the application to store the github username on the database.
A few days ago I deployed a new version of FS with github login enabled, but with "storeGithubUsername" set to false.
A few users registered their github accounts, and now the database has their github ids, but not their usernames.
You can se in my profile that I have github as a "connected account" but there's no link to my github page.
I need it to make the link point to https://github.com/tonylampada
I'm ready to deploy a new version that fixes this, by setting the "storeGithubUsername" (that's not what it is called, I'm just simplifying here) to true.
But I'd like to patch the database with the already github-registered users. I have their github ids, but not their github usernames.

[Assistant]
We need to do this on Gitter to deal with the situation where a user has changed their username on GitHub and we get a 404 response when querying their old username.
Here's an undocumented endpoint, so use as your own peril, but it does work for now.
Use the endpoint: https://api.github.com/user/:id, where :id is the ID of the user.
Similar endpoints exist for repos and orgs, at
https://api.github.com/repositories/:id and https://api.github.com/organizations/:id respectively.
Note that the new repository redirects preview API only supports repositories, not renamed users or organizations. In fact, the HTTP 301 redirect actually points to https://api.github.com/repositories/:id, so there's a good chance that these "ID" endpoints may in fact become official soon.


[System] You are a helpful assistant.

[User] git-log - Show commit logs  --since=<date>  --after=<date>

[Assistant] Show commits more recent than a specific date.


[System] You are a helpful assistant.

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

[Assistant]
records the current commit to be tested when you run git bisect
--no-checkout .


[System] You are a helpful assistant.

[User]
Adding commits to another person's pull request on GitHub
My project on GitHub has received a pull request. The pull request only partly fixes the issue that it's addressing. I've pulled in the changes to a local branch and added some commits of my own.
I'd now like to push those commits back to my remote repo and have them show up on the pull request, but without merging them into the target branch. I'd like to keep the pull request open for further review and discussion, and potentially further commits.
Is there a way I can add commits to the pull request without merging them into the target branch and therefore closing the pull request?

[Assistant]
As long as the original author has clicked the checkbox in the bottom right:

If that box is checked, then you can push back to the original branch without needing to add a remote by using:
git push [email protected]:user/repo local_branch_name:remote_branch_name

This is particularly useful if you're using a tool like hub where you can check out a pull request without needing to add a remote.
Edit: You also need to have write access to the repository where the PR has been opened.
Further Edit: The new command line tool from GitHub does a good job of checking out PRs so that you can just use git push as is to push updates to remotes (assuming you have permission).


[System] You are a helpful assistant.

[User]
Setting up sublimetext 3 as git commit text editor
I'm having trouble setting up sublime as my git commit message editor.
Using:
git config --global core.editor "subl"

Error:
error: cannot run subl: No such file or directory
error: unable to start editor 'subl'
Please supply the message using either -m or -F option.
subl work perfectly otherwise.

[Assistant]
For what it's worth, here's how I solved it:
1) Run in Terminal:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

This adds a subl alias to /usr/local/bin/ pointing to Sublime Text 3 app’s binary file. Now running subl in Terminal will launch Sublime Text 3 app.
2) Run in Terminal:
git config --global core.editor "subl -n -w"

This adds editor = subl -n -w to the [core] section of the ~/.gitconfig file. Now running git commit in Terminal will launch Sublime Text 3 app (subl) in a new window (-n), and the command line will wait (-w) until the commit message is saved and closed.
Image of final workflow added in response to clarifying question in comments below:

Official Sublime Text 3 doc: http://www.sublimetext.com/docs/3/osx_command_line.html


[System] You are a helpful assistant.

[User]
VSTS - prevent push to master but allow PR merge
We have branch policies set up in VSTS to prevent pull requests being merged into master unless a build passes and work items are linked. However, I can't work out how to prevent developers pushing directly to master. Setting the "Contribute" permission to Deny does not allow pull requests to be merged.
All developers should be allowed to merge PRs into master but none should be permitted to push directly to master. Is this possible?

[Assistant]
Branch policies already do exactly what you're saying. When a branch policy is in place, PRs are required.
Make sure your developers don't have the "Exempt From Policy Enforcement" permission.


[System] You are a helpful assistant.

[User]
markdown link opening in new tab

Is there a way to open the below markdown link in new tab? I've got some result from markdown target=“_blank”, but in my case it's different have used  <> symbol to projected the link.
http://google.com
Not used the usual format

(name)[linkname]

Used

<>

Inside this projected the link name. Is possible to open this link in new tab?

[Assistant]
The kramdown syntax:
[link name](url_link){:target="_blank"}

can be parsed into HTML using the kramdown online editor:
https://kramdown.herokuapp.com/
Then you can paste the HTML syntax into your markdown document.
I used it because I already had quite a few kramdown references, and wanted to avoid retyping them in HTML.


[System] You are a helpful assistant.

[User]
Git: "Corrupt loose object"
Whenever I pull from my remote, I get the following error about compression. When I run the manual compression, I get the same:
$ git gc
error: Could not read 3813783126d41a3200b35b6681357c213352ab31
fatal: bad tree object 3813783126d41a3200b35b6681357c213352ab31
error: failed to run repack

Does anyone know, what to do about that?
From cat-file I get this:
$ git cat-file -t 3813783126d41a3200b35b6681357c213352ab31
error: unable to find 3813783126d41a3200b35b6681357c213352ab31
fatal: git cat-file 3813783126d41a3200b35b6681357c213352ab31: bad file

And from git fsck I get this ( don't know if it's actually related):
$ git fsck
error: inflate: data stream error (invalid distance too far back)
error: corrupt loose object '45ba4ceb93bc812ef20a6630bb27e9e0b33a012a'
fatal: loose object 45ba4ceb93bc812ef20a6630bb27e9e0b33a012a (stored in .git/objects/45/ba4ceb93bc812ef20a6630bb27e9e0b33a012a) is corrupted

Can anyone help me decipher this?

[Assistant]
I had the same problem (don't know why).
This fix requires access to an uncorrupted remote copy of the repository, and will keep your locally working copy intact.
But it has some drawbacks:

You will lose the record of any commits that were not pushed, and will have to recommit them.
You will lose any stashes.

The fix
Execute these commands from the parent directory above your repo (replace 'foo' with the name of your project folder):

Create a backup of the corrupt directory:
cp -R foo foo-backup
Make a new clone of the remote repository to a new directory:
git clone [email protected]:foo foo-newclone
Delete the corrupt .git subdirectory:
rm -rf foo/.git
Move the newly cloned .git subdirectory into foo:
mv foo-newclone/.git foo
Delete the rest of the temporary new clone:
rm -rf foo-newclone

On Windows you will need to use:

copy instead of cp -R
rmdir /S instead of rm -rf
move instead of mv

Now foo has its original .git subdirectory back, but all the local changes are still there. git status, commit, pull, push, etc. work again as they should.


[System] You are a helpful assistant.

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

[Assistant]
Don’t add the file(s), but only refresh their stat()
information in the index.


[System] You are a helpful assistant.

[User]
Get Branch name in gitlab ci

In my Gitlab CI, I have a stage that triggers another stage by api call trigger and  I want to pass the current branch name as parameter to the other project holding the trigger. I used the CI_COMMIT_REF_NAME for this, it seemed to work, but now that I call the stage only when merging the branch to master, the CI_COMMIT_REF_NAME always says "master".
In the documentation it says "The branch or tag name for which project is built", do I understand it correctly that it kind of holds the target branch of my working branch?
I tried to get the current branch in gitlab ci with git symbolic-ref HEAD | sed 's!refs\/heads\/!!' as well but it was empty.
Is CI_COMMIT_REF_NAME the variable I am looking for and something is going wrong or do I need something else?
Thanks in advance.

[Assistant]
I'm not sure what you mean by “a stage that triggers another stage by api call trigger”. But, generally speaking, GitLab CI jobs are part of a CI pipeline, and CI pipelines are created for a branch or tag.
The CI_COMMIT_REF_NAME variable contains the name of the branch or tag that the pipeline was created for.
The CI_MERGE_REQUEST_TARGET_BRANCH_NAME is "The target branch name of the merge request."
from GitLab Predefined Variables reference


[System] You are a helpful assistant.

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

[Assistant]
An integer parameter specifies a cut-off percent (3% by default).
Directories contributing less than this percentage of the changes
are not shown in the output.


[System] You are a helpful assistant.

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

[Assistant]
Only perform tests on the working directory to make sure
untracked cache can be used. You have to manually enable
untracked cache using --untracked-cache or --force-untracked-cache or the core.untrackedCache configuration variable afterwards if you really want to use
it. If a test fails the exit code is 1 and a message
explains what is not working as needed, otherwise the exit
code is 0 and OK is printed.


[System] You are a helpful assistant.

[User]
Using vim for git commit messages broken after updating janus
After updating the janus vim distribution there appears to be a problem with using vim for commit messages. The best example of this is when doing a git pull to get someone else's changes. The vim editor is displayed, I type my commit message, I enter :wq but instead of the commit working, I get the following error message:
error: There was a problem with the editor 'vi'.
Not committing merge; use 'git commit' to complete the merge.

I then have to manually commit :(
How do I get git to play nicely with vim?

[Assistant]
After a bit of googling, it turns out that the answer is to run the following:
git config --global core.editor $(which vim)


[System] You are a helpful assistant.

[User]
What are the differences between "git commit" and "git push"?
In a Git tutorial I'm going through, git commit is used to store the changes you've made.
What is git push used for then?

[Assistant]
Basically, git commit "records changes to the repository" while git push "updates remote refs along with associated objects". So the first one is used in connection with your local repository, while the latter one is used to interact with a remote repository.
Here is a nice picture from Oliver Steele, that explains the Git model and the commands:

Read more about git push and git pull on Pushing and pulling (the article I referred to first).


[System] You are a helpful assistant.

[User]
Git still showing deleted files after a commit
How can I remove deleted files from my Git repo?
I've deleted a folder of a JavaScript library, which contained many files. I then went to commit the changes like so:
git add .
git commit "message"
git status

But it shows all those files as "deleted ....".
How can I make them go away?

[Assistant]
This will add deletes as well.
git add -u .

Check what's staged to be committed with:
git status


[System] You are a helpful assistant.

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

[Assistant]
The <eolinfo> (see the description of the --eol option) of
the contents in the index or in the worktree for the path.


[System] You are a helpful assistant.

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

[Assistant] Do everything except actually send the emails.


[System] You are a helpful assistant.

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

[Assistant] Use IPv4 addresses only, ignoring IPv6 addresses.


[System] You are a helpful assistant.

[User] git-ls-files - Show information about files in the index and the working tree  --format=<format>

[Assistant]
A string that interpolates %(fieldname) from the result being shown.
It also interpolates %% to % , and %xx where xx are hex digits
interpolates to character with hex code xx ; for example %00 interpolates to \0 (NUL), %09 to \t (TAB) and %0a to \n (LF).
--format cannot be combined with -s , -o , -k , -t , --resolve-undo and --eol .


[System] You are a helpful assistant.

[User] git-config - Get and set repository or global options  http.proxySSLCertPasswordProtected

[Assistant]
Enable Git’s password prompt for the proxy SSL certificate.  Otherwise OpenSSL
will prompt the user, possibly many times, if the certificate or private key
is encrypted. Can be overridden by the GIT_PROXY_SSL_CERT_PASSWORD_PROTECTED environment variable.


[System] You are a helpful assistant.

[User] git-notes - Add or inspect object notes  -n  --dry-run

[Assistant]
Do not remove anything; just report the object names whose notes
would be removed.


[System] You are a helpful assistant.

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

[Assistant] A portable graphical interface to Git


[System] You are a helpful assistant.

[User] git-difftool - Show changes using common diff tools  --skip-to=<file>

[Assistant]
Start showing the diff for the given path, skipping all
the paths before it.