messages
listlengths
3
3
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Is it okay to use GitHub Secrets with a public repo?\n\nI have a private repo with a GitHub Action that pushes the code to an AWS S3 bucket when there's a new push to the master branch. I need a pair of access keys to be able to push the contents and I'm storing them as GitHub Secrets and referencing them as environment variables in the build script. Now I would like to make this repo public in the near future, and I was wondering if it's a safe thing to do. The workflow (.github/workflows/main.yml) itself for the action is indeed publicly visible and what it does, but it only has the single command aws s3 cp myfile s3://my-bucket and absolutely no access keys in the code itself. \nIs it safe to use GitHub Secrets for the Actions in a public repo? I am the sole owner and only contributor, this will not change in the future. I might switch to CodePipeline with a webhook later but wanted to try GitHub Actions first. Thanks." }, { "role": "assistant", "content": "Yes, secrets are safe to use in public repositories but there are some things you should be careful about.\n\nAll secrets are automatically masked in build logs and show as ***. However, if during your workflow you create a sensitive credential from a secret (e.g. base64 an API key) then you should mask the new value so it doesn't leak in the build log.\necho \"::add-mask::My sensitive value\"\n\n\nIf you are very concerned about the security of your secrets, I would also suggest not using third party GitHub actions directly by following the action's tags or branches. Fork the action and use your fork in workflows. This will prevent the possibility of someone modifying an action you are using to capture secrets being used by the action, and send them to some external server under their control.\nAlternatively, use the action directly and reference the commit hash for the version you want to target.\n- uses: thirdparty/foo-action@172ec762f2ac8e050062398456fccd30444f8f30\n\n\nUse two-factor authentication (2FA) on your account. If your account is compromised, it's trivial for an attacker to create a workflow and export your secrets.\n\nRepository collaborators or any organization users with write access are able to create a workflow to export secrets. So manage access to your repository carefully.\n\n\nPoints related to pull requests:\n\nPublic repository pull_request events triggered by forks do not have access to secrets, except for the default GITHUB_TOKEN. Additionally, The GITHUB_TOKEN has read-only access when an event is triggered by a forked repository. These are intentional restrictions enforced by GitHub Actions to prevent an attacker creating a pull request containing a workflow that captures secrets, or uses secrets to perform operations.\nThe pull_request_target event does not have secret restrictions for events triggered by forks. By default it checks out the last commit on the base branch, but it is possible to checkout the pull request HEAD. Choosing to do this requires extreme caution. Passing secrets to any code that could be modified in a pull request could allow an attacker to write code to export secrets." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "\"Host key verification failed\" on Gitlab_ci although ssh_key is present\n\n\"Host key verification failed.\" on Gitlab_ci when running \"ssh name@server\"\nHere's a part of my gitlab_ci which is supposed to login to my server and run scripts from the repo:\nscript:\n - which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )\n - eval $(ssh-agent -s)\n - ssh-add <(echo -e \"$SSH_PRIVATE_KEY\")\n\n\n - echo \"debug\"\n - echo \"$SSH_PRIVATE_KEY\" # all is ok here, it'll be printed\n - echo \"debug\"\n\n\n # - here comes an error\n - (cat ./script/script1.sh) | ssh -t -t $SSH_USERNAME@$SSH_HOST\n\nAnd the errror:\n Host key verification failed.\n ERROR: Job failed: exit code 1\n\nWhy the error? The variables are set. \nThe private key does work when I'm doing the same thing manually from my local computer and Gitlab." }, { "role": "assistant", "content": "In addition of Git error: “Host Key Verification Failed” when connecting to remote repository, check your .known_hosts file.\nIf that same private key is working locally, that might be because, locally, your ~/.ssh/known_hosts file does include the ssh_keyscan of the remote server you want to connect to.\nMake sure your GitLab CI job does too." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-diff - Show changes between commits, commit and working tree, etc diff.<driver>.wordRegex" }, { "role": "assistant", "content": "The regular expression that the diff driver should use to\nsplit words in a line. See gitattributes for\ndetails." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-diff-index - Compare a tree to the working tree or index dimmed-zebra" }, { "role": "assistant", "content": "Similar to zebra , but additional dimming of uninteresting parts\nof moved code is performed. The bordering lines of two adjacent\nblocks are considered interesting, the rest is uninteresting. dimmed_zebra is a deprecated synonym." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git - the stupid content tracker -p --paginate" }, { "role": "assistant", "content": "Pipe all output into less (or if set, $PAGER) if standard\noutput is a terminal. This overrides the pager.<cmd> configuration options (see the \"Configuration Mechanism\" section\nbelow)." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to detect if test is running on GitLab CI server\n\nI have a test, which is using MySQL database configured and running on gitlab CI server (gitlab-ci.yml). I want that test to be disabled when it's running locally (it's using in-memory database instead). Is there any way to check if the test is running on GitLab Ci server? Something like:\nif(isRunningOnGitlabCi()) {\n Assert.assertThat(...);\n}\n\nMaybe there's environmental variable, which I can check ?" }, { "role": "assistant", "content": "Gitlab CI defines a large number of environment variables; you could use e.g. GITLAB_CI.\nSomething like:\nif(System.getenv(\"GITLAB_CI\") != null) {\n Assert.assertThat(...);\n}" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-fetch - Download objects and refs from another repository -4 --ipv4" }, { "role": "assistant", "content": "Use IPv4 addresses only, ignoring IPv6 addresses." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-format-patch - Prepare patches for e-mail submission --default-prefix" }, { "role": "assistant", "content": "Use the default source and destination prefixes (\"a/\" and \"b/\").\nThis overrides configuration variables such as diff.noprefix , diff.srcPrefix , diff.dstPrefix , and diff.mnemonicPrefix (see git-config (1))." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How do I make a GitHub Action matrix element conditional?\n\nI have a workflow that uses 'strategy' = 'matrix' along with a list of specific configurations to build.\nHere is my workflow file:\n#\n# build-N-test-v2.1-Dev and build-N-test-v2.1-Release are nearly\n# identical, but a few tests are commented out (to not needlessly stress CI system)\n# for v2.1-Dev builds\n#\n# NOTE: I've tried many tricks - none which seem to work - to get this working on one file with one\n# workflow and tests\n# https://github.community/t/what-is-the-correct-if-condition-syntax-for-checking-matrix-os-version/16221\n# https://github.community/t/how-to-conditionally-include-exclude-items-in-matrix-eg-based-on-branch/16853\n#\n# but none seem to work\n#\n\nname: build-N-test-v2.1-Dev\n\non:\n push:\n branches:\n - v2.1-Dev\n #- v2.1-Release\n workflow_dispatch:\n inputs:\n ignored:\n description: \"ignored\"\n required: false\n default: \"\"\n\n## NB: JOBS section IDENTICAL between v2.1-Dev and 2.1-Release files EXCEPT that on v2.1-Dev file\n## comment out all entries marked with includeInDevBranchBuilds: false\njobs:\n build-n-test-Linux:\n runs-on: ${{ matrix.runs_on }}\n strategy:\n #\n # Configuration notes\n # o --debug-symbols false to reduce build disk size (and we aren't debugging anyhow) in many debug configurations\n #\n matrix:\n include:\n # ## SADLY: Container operations are only supported on Linux runners\n # - displayTargetName: windows-DBG\n # os: windows\n # compiler: g++-8\n # runs_on: windows-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-windows-cygwin-vs2k19\n # cpp_version: c++17\n # config_name: Debug\n # extra_config_args: --apply-default-debug-flags --trace2file enable\n\n ## centos 8\n - displayTargetName: centos-8\n os: unix\n compiler: g++\n runs_on: ubuntu-latest\n container_image: sophistsolutionsinc/stroika-buildvm-centos-8-small\n cpp_version: c++17\n config_name: Release\n extra_config_args: --apply-default-release-flags --trace2file enable\n includeInDevBranchBuilds: true\n\n ## ubuntu 18.04\n - displayTargetName: ubuntu-18.04-g++-8 (Debug)\n os: unix\n compiler: g++-8\n runs_on: ubuntu-latest\n container_image: sophistsolutionsinc/stroika-buildvm-ubuntu1804-regression-tests\n cpp_version: c++17\n config_name: Debug\n extra_config_args: --apply-default-debug-flags --trace2file enable --debug-symbols false\n includeInDevBranchBuilds: true\n\n - displayTargetName: ubuntu-18.04-cross-compile-raspberrypi (Debug)\n os: unix\n compiler: g++-8\n runs_on: ubuntu-latest\n container_image: sophistsolutionsinc/stroika-buildvm-ubuntu1804-regression-tests\n cpp_version: c++17\n config_name: Debug\n extra_config_args: --apply-default-release-flags --trace2file enable --compiler-driver arm-linux-gnueabihf-g++-8 --cross-compiling true\n includeInDevBranchBuilds: true\n\n # ubuntu 20.04\n # - displayTargetName: ubuntu-20.04-g++-9 (Debug)\n # os: unix\n # compiler: g++-9\n # runs_on: ubuntu-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\n # cpp_version: c++17\n # config_name: Debug\n # extra_config_args: --apply-default-debug-flags --trace2file enable --debug-symbols false\n # includeInDevBranchBuilds: false\n\n # - displayTargetName: ubuntu-20.04-g++-10 (Debug)\n # os: unix\n # compiler: g++-10\n # runs_on: ubuntu-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\n # cpp_version: c++17\n # config_name: Debug\n # extra_config_args: --apply-default-debug-flags --trace2file enable --debug-symbols false\n # includeInDevBranchBuilds: false\n\n - displayTargetName: ubuntu-20.04-g++-10\n os: unix\n compiler: g++-10\n runs_on: ubuntu-latest\n container_image: sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\n cpp_version: c++17\n config_name: Release\n extra_config_args: --apply-default-release-flags --trace2file enable\n includeInDevBranchBuilds: true\n\n # - displayTargetName: ubuntu-20.04-g++-10-c++2a\n # os: unix\n # compiler: g++-10\n # runs_on: ubuntu-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\n # cpp_version: c++2a\n # config_name: Release\n # extra_config_args: --apply-default-release-flags --trace2file enable\n # includeInDevBranchBuilds: false\n\n # - displayTargetName: ubuntu-20.04-clang++-10\n # os: unix\n # compiler: clang++-10\n # runs_on: ubuntu-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\n # cpp_version: c++17\n # config_name: Release\n # extra_config_args: --apply-default-release-flags --trace2file enable\n # includeInDevBranchBuilds: false\n\n ### ATTEMPT TO COMPRESS 2 workflow files into one, but so far not working\n ### SEE\n ### https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional/65385385#65385385\n ###\n #if: github.ref == 'refs/heads/v2.1-Release' || matrix.includeInDevBranchBuilds\n env:\n # vm has 2 virtual CPUs, but 8GB ram, so jobs=5 (empirical), and QUICK_BUILD avoids some internal testing\n MAKEFLAGS: \"--jobs=3 QUICK_BUILD=1\"\n container: ${{ matrix.container_image }}\n steps:\n - uses: actions/checkout@v2\n - name: Build System Info\n if: ${{ matrix.os=='unix' }}\n run: |\n lsb_release -d 2>/dev/null || true\n echo \"CWD=\" `pwd`\n echo \"nproc=\" `nproc`\n grep \"model name\" /proc/cpuinfo | head -1\n grep processor /proc/cpuinfo | wc -l\n grep MemTotal /proc/meminfo\n df -h\n - name: Build System Info (Windows)\n if: ${{ matrix.os=='windows' }}\n run: |\n echo \"CWD=\" `pwd`\n df -h\n - name: Configure ${{ matrix.config_name }}\n run: |\n ./configure ${{ matrix.config_name }} --compiler-driver ${{ matrix.compiler }} ${{ matrix.extra_config_args }} --cppstd-version ${{ matrix.cpp_version }}\n cat ConfigurationFiles/${{ matrix.config_name }}.xml\n # Break out third-party-components to do clean so we dont run out of disk space, and break out TPC AND library\n # to show the summary time for each part\n - name: Make third-party-components\n run: |\n make third-party-components\n make clean\n - name: Make libraries\n run: make libraries\n - name: Make all\n run: make all\n - name: Run Tests\n run: make run-tests\n - name: Archive Samples Results\n uses: actions/upload-artifact@v2\n with:\n name: Sample apps (${{ matrix.displayTargetName }})\n path: |\n Builds/${{ matrix.config_name }}/Samples-*\n - name: Archive Log Results\n uses: actions/upload-artifact@v2\n with:\n name: Log Data (${{ matrix.displayTargetName }})\n path: |\n Builds/${{ matrix.config_name }}/PerformanceDump.txt\n /tmp/Trace*.txt\n\n build-n-test-MacOS:\n runs-on: ${{ matrix.runs_on }}\n strategy:\n matrix:\n # Add to extra_config_args for build speed: --Xerces no --OpenSSL no --lzma no --boost no\n include:\n - displayTargetName: MacOS-Debug\n os: macos-10.15\n runs_on: macos-10.15\n config_name: Debug\n extra_config_args: --apply-default-debug-flags --trace2file enable\n includeInDevBranchBuilds: true\n # - displayTargetName: MacOS\n # os: macos-10.15\n # runs_on: macos-10.15\n # config_name: Release\n # extra_config_args: --apply-default-release-flags --trace2file enable\n # includeInDevBranchBuilds: false\n env:\n # vm has 2 virtual CPUs, but 8GB ram, so jobs=5 (empirical), and QUICK_BUILD avoids some internal testing\n MAKEFLAGS: \"--jobs=3 QUICK_BUILD=1\"\n steps:\n - uses: actions/checkout@v2\n - name: Build System Info\n run: |\n echo \"CWD: `pwd`\"\n df -h\n system_profiler SPSoftwareDataType\n sw_vers\n # If we had docker ability, most of these would be built into a docker file\n - name: Install Basic Build requirements\n run: |\n brew install gnu-sed\n brew install p7zip\n brew install automake\n make install-realpath\n - name: Configure\n run: |\n ./configure ${{ matrix.config_name }} ${{ matrix.extra_config_args }}\n cat ConfigurationFiles/${{ matrix.config_name }}.xml\n - name: Build third-party-components\n run: |\n make third-party-components\n make clean\n - name: Build Library\n run: |\n make libraries\n - name: Build All\n run: |\n make all\n - name: Run-Tests\n run: |\n make run-tests\n - name: Workaround GitHub-Actions-MacOS Issue with env.TMPDIR\n run: |\n mkdir /tmp/LOGS-ARCHIVE\n cp $TMPDIR/Trace*.txt /tmp/LOGS-ARCHIVE\n - name: DEBUG Workaround GitHub-Actions-MacOS Issue with env.TMPDIR\n run: |\n echo \"TMPDIR=$TMPDIR\"\n echo \"TMPDIR using ENV.TMPDIR=${{ env.TMPDIR }}\"\n # Just the echo line above shows empty, and then the ls line causes exit 1/failure\n #ls -l ${{ env.TMPDIR }}/Trace*.txt\n #if this gets fixed, then lose Workaround GitHub-Actions-MacOS, and directly reference ${{ env.TMPDIR }}/Trace*.txt in Archive Log Results\n - name: Build System Info\n run: |\n df -h\n - name: Archive Log Results\n uses: actions/upload-artifact@v2\n with:\n name: Log Results (${{ matrix.displayTargetName }})\n path: |\n Builds/${{ matrix.config_name }}/PerformanceDump.txt\n /tmp/LOGS-ARCHIVE\n #${{ env.TMPDIR }}/Trace*.txt\n - name: Archive Sample Results\n uses: actions/upload-artifact@v2\n with:\n name: Samples (${{ matrix.displayTargetName }})\n path: |\n Builds/${{ matrix.config_name }}/Samples-*\n\n build-n-test-Windows:\n runs-on: ${{ matrix.runs_on }}\n strategy:\n matrix:\n # Add to extra_config_args for build speed: --Xerces no --OpenSSL no --lzma no --boost no\n include:\n - displayTargetName: windows-x86-Debug\n os: windows\n runs_on: windows-latest\n container_image: sophistsolutionsinc/stroika-buildvm-windows-cygwin-vs2k19\n config_name: Debug\n extra_config_args: --arch x86 --apply-default-debug-flags --trace2file enable\n includeInDevBranchBuilds: true\n # - displayTargetName: windows-x86-Release\n # os: windows\n # runs_on: windows-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-windows-cygwin-vs2k19\n # config_name: Release\n # extra_config_args: --arch x86 --apply-default-release-flags --trace2file enable\n # includeInDevBranchBuilds: false\n # - displayTargetName: windows-x86_64-Debug\n # os: windows\n # runs_on: windows-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-windows-cygwin-vs2k19\n # config_name: Debug\n # extra_config_args: --arch x86_64 --apply-default-debug-flags --trace2file enable\n # includeInDevBranchBuilds: false\n # - displayTargetName: windows-x86_64-Release\n # os: windows\n # runs_on: windows-latest\n # container_image: sophistsolutionsinc/stroika-buildvm-windows-cygwin-vs2k19\n # config_name: Release\n # extra_config_args: --arch x86 --apply-default-release-flags --trace2file enable\n # includeInDevBranchBuilds: false\n env:\n # vm has 2 virtual CPUs, but 8GB ram, so jobs=5 (empirical), and QUICK_BUILD avoids some internal testing\n MAKEFLAGS: \"--jobs=3 QUICK_BUILD=1\"\n ARTIFACTS_DIR: \"c:/Artifacts/\"\n steps:\n - uses: actions/checkout@v2\n # https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions\n - name: Extract branch name\n shell: bash\n run: echo \"##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})\"\n id: extract_branch\n - name: Build System Info\n shell: \"bash\"\n run: |\n echo \"CWD: `pwd`\"\n df -h\n systeminfo\n echo NUMBER_OF_PROCESSORS=$NUMBER_OF_PROCESSORS\n - name: docker pull ${{ matrix.container_image }}\n run: docker pull ${{ matrix.container_image }}\n - name: Start docker build environment\n run: |\n docker run --tty --memory 5G --cpus 2 --storage-opt 'size=50GB' --detach --name buildContainer ${{ matrix.container_image }}\n - name: Print Info about docker system\n shell: \"bash\"\n run: |\n docker ps -a\n docker exec buildContainer systeminfo\n docker exec buildContainer df -h\n - name: Git Checkout\n shell: \"bash\"\n run: |\n docker exec buildContainer sh -c \"git clone https://github.com/SophistSolutions/Stroika.git && cd Stroika && git checkout ${{ steps.extract_branch.outputs.branch }}\"\n - name: Configure\n shell: \"bash\"\n run: |\n docker exec --workdir c:/Stroika buildContainer sh -c \"./configure ${{ matrix.config_name }} ${{ matrix.extra_config_args }}\"\n docker exec --workdir c:/Stroika buildContainer cat ConfigurationFiles/${{ matrix.config_name }}.xml\n - name: Build\n shell: \"bash\"\n run: |\n docker exec --workdir c:/Stroika --env MAKEFLAGS=\"$MAKEFLAGS\" buildContainer make all\n - name: Run-Tests\n shell: \"bash\"\n run: |\n docker exec --workdir c:/Stroika --env MAKEFLAGS=\"$MAKEFLAGS\" buildContainer make run-tests\n - name: Build System Info\n shell: \"bash\"\n run: |\n df -h\n docker exec buildContainer df -h\n - name: Copy Build Artifacts\n shell: \"bash\"\n # due to flaws in docker (windows must stop) - and cp no wildcards\n run: |\n docker exec --workdir c:/Stroika buildContainer bash -c 'mkdir TRACE_LOGS && cp $TEMP/Trace*.txt TRACE_LOGS/'\n docker stop buildContainer\n docker cp buildContainer:Stroika/Builds/${{ matrix.config_name }}/ $ARTIFACTS_DIR 2> /dev/null\n docker cp buildContainer:Stroika/TRACE_LOGS $ARTIFACTS_DIR 2> /dev/null\n rm -rf $ARTIFACTS_DIR/{ThirdPartyComponents,Tests,*.lib}\n - name: Archive Log Results\n uses: actions/upload-artifact@v2\n with:\n name: Log Results (${{ matrix.displayTargetName }})\n path: |\n ${{ env.ARTIFACTS_DIR }}PerformanceDump.txt\n ${{ env.ARTIFACTS_DIR }}TRACE_LOGS\n - name: Archive Sample Results\n uses: actions/upload-artifact@v2\n with:\n name: Samples (${{ matrix.displayTargetName }})\n path: |\n ${{ env.ARTIFACTS_DIR }}Samples-*\n\nHowever, I'd like to only build some of the configurations only when the branch is v2.1-Release. That is - for the most part - just build one or two configurations but build a bunch more on release.\nI've accomplished this by cloning the script (workflow) and renaming a few things and commenting things out, but it would be nice if the mechanism worked with matrix elements.\nI realize there is an if feature that can be added to each step, but that would create tons of jobs with disabled steps. What I want is to not spin up those jobs at all for each matrix element that has the if part evaluates false." }, { "role": "assistant", "content": "TLDR: you can do what you want with one workflow by filtering the configurations you want to use in a prior build job/step, and using the result of that filtering as the matrix value in your build-n-test job.\n\nLonger version:\nYou can create a job (i.e. build-n-test) where the value of strategy.matrix is different based off of some criteria by setting the value of strategy.matrix to the deserialized output of a previous job (i.e. matrix_prep). This previous job would have the responsibility of constructing the matrix value as per your custom criteria. The following yaml demonstrates this (a copy has been included later on with comments added in for explanation):\nname: Configurable Build Matrix\n\non: push\njobs:\n matrix_prep:\n runs-on: ubuntu-latest\n outputs:\n matrix: ${{ steps.set-matrix.outputs.matrix }}\n steps:\n - name: Check out code into the Go module directory\n uses: actions/checkout@v2\n - id: set-matrix\n run: |\n branchName=$(echo '${{ github.ref }}' | sed 's,refs/heads/,,g') \n matrix=$(jq --arg branchName \"$branchName\" 'map( \n . | select((.runOn==$branchName) or (.runOn==\"always\"))\n )' matrix_includes.json) \n echo \"matrix={\\\"include\\\":$(echo $matrix)}\" >> $GITHUB_OUTPUT\n build-n-test:\n needs: matrix_prep\n runs-on: ${{ matrix.runs_on }}\n strategy:\n matrix: ${{fromJson(needs.matrix_prep.outputs.matrix)}}\n steps: \n - run: echo \"Hello ${{ matrix.someValue }}\"\n\nThe contents of the matrix_includes.json file used in the set-matrix task can be found after this paragraph. To see what the matrix configuration from the question would look like as JSON, please look near the bottom of this answer. I went the route of having a JSON file separate from the workflow definition itself because I found that including the raw JSON in the workflow itself was very messy (especially if the JSON file was large).\n[\n {\n \"runs_on\":\"ubuntu-16.04\",\n \"someValue\":\"Foo\",\n \"runOn\":\"always\"\n },\n {\n \"runs_on\":\"ubuntu-18.04\",\n \"someValue\":\"Bar\",\n \"runOn\":\"v2.1-Release\"\n },\n {\n \"runs_on\":\"ubuntu-20.04\",\n \"someValue\":\"Hello again\",\n \"runOn\":\"v2.1-Release\"\n }\n]\n\nUsing the setup above, one configuration will be included for all builds, and two will only be included if the branch name matches v2.1-Release. With some tweaks to the sed and jq options in the Workflow file, the branch name restrictions could be made looser such that you could have configurations run for all branches that include -Release (instead of just for a single branch). I may include this in this answer if there is interest (as it does not necessarily match your current question).\nset-matrix Job Explanation\nAs far as the set-matrix task is concerned, please refer to the following notes:\n# ${{ github.ref }} returns the full git ref. As such, 'refs/heads/` \n# should be stripped for easier future use.\nbranchName=$(echo '${{ github.ref }}' | sed 's,refs/heads/,,g') \n# Use jq to read in a json file that represents the matrix configuration. Each\n# block has a 'runOn' property. The jq filter is setup to only output items that \n# are set to 'always' or that have a branch name that matches the current branch.\nmatrix=$(jq --arg branchName \"$branchName\" 'map(\n . | select((.runOn==$branchName) or (.runOn==\"always\")) \n)' matrix_includes.json) \n# This 'echo' uses a special syntax so that the output of this job \n# is set correctly.\necho \"matrix={\\\"include\\\":$(echo $matrix)}\" >> $GITHUB_OUTPUT\n\nWorkflow explanation\nThe following yaml content should be the same as above with some additional comments to help explain things:\nname: Configurable Build Matrix\non: push\njobs:\n matrix_prep:\n # Using a separate job and agent so as to be able to use tools \n # like 'sed' and 'jq'.\n runs-on: ubuntu-latest\n # Defining outputs of a job allows for easier consumption and use.\n outputs:\n matrix: ${{ steps.set-matrix.outputs.matrix }}\n steps:\n # Checking out code as the set-matrix step utilizes a \n # file named matrix_includes.json.\n - name: Check out code into the Go module directory\n uses: actions/checkout@v2\n # This step is explained more in a following section\n - id: set-matrix\n run: |\n branchName=$(echo '${{ github.ref }}' | sed 's,refs/heads/,,g') \n matrix=$(jq --arg branchName \"$branchName\" 'map(\n . | select((.runOn==$branchName) or (.runOn==\"always\")) \n )' matrix_includes.json) \n echo \"matrix={\\\"include\\\":$(echo $matrix)}\" >> $GITHUB_OUTPUT\n build-n-test:\n # By stating 'needs' here, the output of 'matrix_prep' is \n # available to this job.\n needs: matrix_prep\n runs-on: ${{ matrix.runs_on }}\n strategy:\n # We need to convert the json string output into an object that the \n # GitHub Workflow expects. Thankfully, the json-schema for Workflows \n # allows 'matrix' to be set to an expression.\n matrix: ${{fromJson(needs.matrix_prep.outputs.matrix)}}\n steps:\n # Output a configuration specific value as proof and as a sanity check\n - run: echo \"Hello ${{ matrix.someValue }}\"\n\nDemonstration\nI put together two files for this demonstration:\n\nThe workflow definition (pasted below)\nA JSON file to contain matrix information (pasted below)\n\nThe following two screenshots are from runs on different branches using the same workflow definition. Please note that the amount of build-n-test Jobs are different between the two:\nBuild for main branch\n\nBuild for v2.1-Release branch\n\nThis is due to the first build occurring on the main branch, and the second occurring on the v2.1-Release branch. As can be seen by the included matrix_includes.json file above, this is to be expected as two configurations are set to run only when the branch is v2.1-Release, and only one configuration is set to run always.\nFurther Detail\nMatrix Configuration Filtering\nThe filtering is accomplished through using jq to select objects from the json array that either have their runOn value set to always or that match the current branchName. This is the slight tweak to your logic that I mentioned earlier: instead of saying includeInDevBranchBuilds, I am using runOn as it seemed to work better for this specific example.\nBranchName\nThe set-matrix step uses a value set from the previous line: branchName=$(echo '${{ github.ref }}' | sed 's,refs/heads/.*-,,g'). This line will strip refs/heads/ from the branch ref and store the result in the value branchName. For example, if your branch is 2.1-Release, branchName will be set to 2.1-Release, and the filter from earlier will then match any objects that have \"runOn\":\"2.1-Release\" or \"runOn\":\"always\".\nThe JSON file\nThe JSON file was created to simulate the content of the includes statement from the workflow that you linked. JSON is used as GitHub Actions have builtin JSON functions. As a sample, the following is my take on converting your matrix:include section to JSON. Please note that I've changed includeInDevBranchBuilds to be runOn, with the values set to either always or v2.1-Release.\n[\n {\n \"displayTargetName\": \"centos-8\",\n \"os\": \"unix\",\n \"compiler\": \"g++\",\n \"runs_on\": \"ubuntu-latest\",\n \"container_image\": \"sophistsolutionsinc/stroika-buildvm-centos-8-small\",\n \"cpp_version\": \"c++17\",\n \"config_name\": \"Release\",\n \"extra_config_args\": \"--apply-default-release-flags --trace2file enable\",\n \"runOn\": \"always\"\n },\n {\n \"displayTargetName\": \"ubuntu-18.04-g++-8 (Debug)\",\n \"os\": \"unix\",\n \"compiler\": \"g++-8\",\n \"runs_on\": \"ubuntu-latest\",\n \"container_image\": \n \"sophistsolutionsinc/stroika-buildvm-ubuntu1804-regression-tests\",\n \"cpp_version\": \"c++17\",\n \"config_name\": \"Debug\",\n \"extra_config_args\": \"--apply-default-debug-flags --trace2file enable\",\n \"runOn\": \"always\"\n },\n {\n \"displayTargetName\": \"ubuntu-20.04-g++-9 (Debug)\",\n \"os\": \"unix\",\n \"compiler\": \"g++-9\",\n \"runs_on\": \"ubuntu-latest\",\n \"container_image\": \n \"sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\",\n \"cpp_version\": \"c++17\",\n \"config_name\": \"Debug\",\n \"extra_config_args\": \"--apply-default-debug-flags --trace2file enable\",\n \"runOn\": \"v2.1-Release\"\n },\n {\n \"displayTargetName\": \"ubuntu-20.04-g++-10 (Debug)\",\n \"os\": \"unix\",\n \"compiler\": \"g++-10\",\n \"runs_on\": \"ubuntu-latest\",\n \"container_image\": \n \"sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\",\n \"cpp_version\": \"c++17\",\n \"config_name\": \"Debug\",\n \"extra_config_args\": \"--apply-default-debug-flags --trace2file enable\",\n \"runOn\": \"v2.1-Release\"\n },\n {\n \"displayTargetName\": \"ubuntu-20.04-g++-10\",\n \"os\": \"unix\",\n \"compiler\": \"g++-10\",\n \"runs_on\": \"ubuntu-latest\",\n \"container_image\": \n \"sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\",\n \"cpp_version\": \"c++17\",\n \"config_name\": \"Release\",\n \"extra_config_args\": \"--apply-default-release-flags --trace2file enable\",\n \"runOn\": \"always\"\n },\n {\n \"displayTargetName\": \"ubuntu-20.04-g++-10-c++2a\",\n \"os\": \"unix\",\n \"compiler\": \"g++-10\",\n \"runs_on\": \"ubuntu-latest\",\n \"container_image\": \n \"sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\",\n \"cpp_version\": \"c++2a\",\n \"config_name\": \"Release\",\n \"extra_config_args\": \"--apply-default-release-flags --trace2file enable\",\n \"runOn\": \"v2.1-Release\"\n },\n {\n \"displayTargetName\": \"ubuntu-20.04-clang++-10\",\n \"os\": \"unix\",\n \"compiler\": \"clang++-10\",\n \"runs_on\": \"ubuntu-latest\",\n \"container_image\": \n \"sophistsolutionsinc/stroika-buildvm-ubuntu2004-regression-tests\",\n \"cpp_version\": \"c++17\",\n \"config_name\": \"Release\",\n \"extra_config_args\": \"--apply-default-release-flags --trace2file enable\",\n \"runOn\": \"v2.1-Release\"\n }\n]" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "GitHub \"fatal: remote origin already exists\"\n\nI am trying to follow along Michael Hartl's Rails tutorial but I've run across an error.\nI signed up at GitHub, issued a new SSH key, and created a new repository. But when I enter the next line into the terminal, I get the following error:\nParkers-MacBook-Pro:.ssh ppreyer$ git remote add origin [email protected]:ppreyer/first_app.git\nfatal: remote origin already exists.\n\nJust wondered if anybody else has run across this problem?" }, { "role": "assistant", "content": "Short version:\nYou should just update the existing remote:\ngit remote set-url origin [email protected]:ppreyer/first_app.git\n\nLong version:\nAs the error message indicates, there is already a remote configured with the same name. So you can either add the new remote with a different name or update the existing one if you don't need it.\nTo add a new remote, called for example github instead of origin (which obviously already exists in your system), do the following:\ngit remote add github [email protected]:ppreyer/first_app.git\n\nRemember though, everywhere in the tutorial you see \"origin\" you should replace it with \"github\". For example $ git push origin master should now be $ git push github master.\nHowever, if you want to see what that already existing origin remote is, you can do a $ git remote -v. If you think this is there by some error, you can update it like so:\ngit remote set-url origin [email protected]:ppreyer/first_app.git" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git - the stupid content tracker gitmailmap" }, { "role": "assistant", "content": "Map author/committer names and/or E-Mail addresses" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Is there a way to gpg sign all previous commits?\nAs the title says, I'm looking for a way to gpg sign all my previous commits in a repository (preferably without typing in my passcode for every commit)." }, { "role": "assistant", "content": "My approach is\ngit rebase --exec \"git commit --amend --no-edit -n -S\" -i 8fd7b22\n\nAll commits started from the next after 8fd7b22 will be rebased with no changes except signing. To change all commits started from the very first one you may use --root (since Git v1.7.12):\ngit rebase --exec \"git commit --amend --no-edit -n -S\" -i --root\n\nTo spread changes to the remote I use\ngit push --force\n\nNote, this will update \"gpg made\" date-time and, for example, GitHub will treat it as commit date. Git itself persists both original and new dates, git log --show-signature gives clear picture of when the original commit was made and when it was signed for the last time." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git - the stupid content tracker git-stripspace" }, { "role": "assistant", "content": "Remove unnecessary whitespace" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How can I push to my fork from a clone of the original repo?\nI created a fork (let's call it myrepo) of another repository (let's call it orirepo) on GitHub. Later, I cloned orirepo.\ngit clone https://github.com/original/orirepo.git\n\nI modified about 20 files, then I staged my change and made a commit\ngit add\ngit commit\n\nHowever, when I tried to push\ngit push\n\nI got this error:\nremote: Permission to original/orirepo.git denied to mylogin.\nfatal: unable to access 'https://github.com/original/orirepo.git/': The requested URL returned error: 403\n\nI know I made a mistake: I should have cloned my fork rather than orirepo, but it's too late for that now.\nHow could I push to my fork rather than to origin/orirepo, which I don't have write access to?" }, { "role": "assistant", "content": "By default, when you clone a repository\n\nthat resides at https://github.com/original/orirepo.git,\nwhose current branch is called master,\n\nthen\n\nthe local config of the resulting clone lists only one remote called origin, which is associated with the URL of the repository you cloned;\nthe local master branch in your clone is set to track origin/master.\n\nTherefore, if you don't modify the config of your clone, Git interprets\ngit push\n\nas\ngit push origin master:origin/master\n\nIn other words, git push attempts to push your local master branch to the master branch that resides on the remote repository (known by your clone as origin). However, you're not allowed to do that, because you don't have write access to that remote repository.\nYou need to\n\neither redefine the origin remote to be associated with your fork, by running\ngit remote set-url origin https://github.com/RemiB/myrepo.git\n\nor, if you want to preserve the original definition of the origin remote, define a new remote (called myrepo, here) that is associated to your fork:\ngit remote add myrepo https://github.com/RemiB/myrepo.git\n\nThen you should be able to push your local master branch to your fork by running\ngit push myrepo master\n\nAnd if you want to tell Git that git push should push to myrepo instead of origin from now on, you should run\ngit push -u myrepo master\n\n\ninstead." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git gui not working after installing in Mac (e.g. Mountain Lion)\nWhen I ran git gui, I got this:\n$ git gui\ngit: 'gui' is not a git command. See 'git --help'.\n\nDid you mean one of these?\n grep\n init\n pull\n push\n\nBut I ran other git commands fine, including gitk. How can I fix this?\nThanks." }, { "role": "assistant", "content": "Edit your git config to an add an entry for gui in the alias section\nnano ~/.gitconfig\n\n\n[alias]\ngui = !sh -c '/usr/local/git/libexec/git-core/git-gui'\n\nEdit 2020\nIt looks like the path in the original answer is now obsolete. Updated instructions:\n\n[alias]\ngui = !sh -c '/usr/local/opt/git/bin/git gui'" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to solve conflicts on GitLab?\n\nI recently worked with git and there was such a question. I made a merge request from the current branch into master. And received such a message: \n\nWhat are the options to allow this, so that the button appeared on the site to accept the merge? If I do local merge then it closes automatically, but I don’t need to. Are there any options?" }, { "role": "assistant", "content": "Normally to resolve issues like this I would do the following locally:\ngit pull origin master\n\nThis should pull the current master from the remote and merge it with your local branch, then you can resolve the conflicts on your local copy, commit that and you should be good to proceed with your merge\nI have since been told that the better way to do this is to rebase, by taking all the changes on your local branch since the most recent common commit on the master, you can apply those changes to the current master, when you're on your local branch you can run:\ngit rebase master\n\nThis will delete your commit and create a new commit with all the changes and you don't need a second commit. This means the git history will be cleaner.\nTo try to avoid this when going forward, try to make sure you pull master before making a new branch so you're up to date when you start. Obviously if you take a while to ready your commit before trying to merge again you might need to pull the master in again to make sure you don't have a conflict first." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-diff - Show changes between commits, commit and working tree, etc diff.wsErrorHighlight" }, { "role": "assistant", "content": "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 . The\nwhitespace errors are colored with color.diff.whitespace .\nThe command line option --ws-error-highlight=<kind> overrides this setting." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options waitingForEditor" }, { "role": "assistant", "content": "Shown when Git is waiting for editor input. Relevant\nwhen e.g. the editor is not launched inside the terminal." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How To Import Tags Into Gitlab\n\nI've just converted our repository from github to an internal gitlab. I started by getting a bare local repository and I have been able to get a new master into gitlab.\nIn my local repository, git tag shows a list of tags that I had on github. But none of the tags are showing up in gitlab.\nI have GitLab 6.6.0.pre fe6c534.\nSo I how do I import my tags into gitlab?" }, { "role": "assistant", "content": "You should push those tags to your remote gitlab:\ngit push --tags\n\nBy default, git push pushed only commits, not tags.\n(See \"Push git commits & tags simultaneously\" for more on that)" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options index.skipHash" }, { "role": "assistant", "content": "When enabled, do not compute the trailing hash for the index file.\nThis accelerates Git commands that manipulate the index, such as git add , git commit , or git status . Instead of storing the\nchecksum, write a trailing set of bytes with value zero, indicating\nthat the computation was skipped. If you enable index.skipHash , then Git clients older than 2.13.0 will\nrefuse to parse the index and Git clients older than 2.40.0 will report an\nerror during git fsck ." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Definitive recommendation for git autocrlf settings\nI use Windows, Mac OS X and linux on a daily basis. I use git in all these environments, pulling from repos that are used by folks with different choices for line endings.\nAre there definitive recommendation for setting core.autocrlf in my situation?" }, { "role": "assistant", "content": "I would recommend, as I did in this SO question, to set it to false.\nIf you can avoid modifying any eol (with your editor), then it would be best to push back your work with those eol unchanged (i.e. \"as you found them\")." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Do all git commands have a dry-run option?\nDo all git commands have a --dry-run option, or one which would indicate what the command would do without actually doing them?" }, { "role": "assistant", "content": "Not every command would naturally support a dry run directly.\n\ngit merge has its own option (git merge --no-commit --no-ff)\nbut git pull does not really need it ('git fetch origin', then a\n'git log master..origin/master', before a git merge origin/master)\n(but git push has a dry-run option)\n\nAs J.C. Hamano summarizes:\n\nThere are things that are not implemented in git because they do not make\n sense, and there are things that are not implemented in git because nobody\n had itch to scratch for.\n To put it differently, we tend to implement only\n things that there are actual, demonstrated needs for from real world and\n only when the addition makes sense as a coherent part of the system.\n\n\niboisver comments:\n\nAnother thing to be aware of is that commands like git add and git rm allow the -n command-line option to specify dry run, while in git commit, the -n option means something completely different.\n So be sure to check the man page\n\ngit commit -n:\n-n\n--no-verify\n\n\nThis option bypasses the pre-commit and commit-msg hooks. See also githooks(5)." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-log - Show commit logs --graph" }, { "role": "assistant", "content": "Draw a text-based graphical representation of the commit history\non the left hand side of the output. This may cause extra lines\nto be printed in between commits, in order for the graph history\nto be drawn properly.\nCannot be combined with --no-walk . This enables parent rewriting, see History Simplification above. This implies the --topo-order option by default, but the --date-order option may also be specified." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git checkout branch from outside\nProblem: I need somehow to checkout an existing branch of a project that is already cloned locally on my file system without being in that particular folder of this project.\nSolution: I'm trying to do the following:\n\ngit clone 'github-project-url' 'file-system-folder'\ngit checkout 'existing-branch' 'file-system-folder'\n\nI do realize that second step is not quite right, but I also am trying to avoid to cd 'file-system-folder'." }, { "role": "assistant", "content": "You can use --git-dir to specify the .git directory to use as the repository, and --work-tree to specify the working tree to to the checkout in. See the git man page for details.\ngit --git-dir=file-system-folder/.git --work-tree=file-system-folder checkout existing-branch" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-rebase - Reapply commits on top of another base tip --verify" }, { "role": "assistant", "content": "Allows the pre-rebase hook to run, which is the default. This option can\nbe used to override --no-verify . See also githooks ." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Understanding the basics of Git and GitHub [closed]\n\nClosed. This question needs to be more focused. It is not currently accepting answers.\n \n \n\n\n\n\n\n\n\n\n\n\n\nWant to improve this question? Update the question so it focuses on one problem only by editing this post.\n\n\nClosed 9 years ago.\n\n\n\n\n\n\n\n Improve this question\n \n\n\n\nI don't fully understand the purpose of using Git or Github; I know it helps to keep track of your changes and it's helpful for people collaborating with other people, but I don't collaborate with anybody so I don't know if this would be helpful for me.\nI usually work as a web designer/developer but I never have to collaborate. I know in Git you have create, push, commit, create branches etc for every repository but...\n\nWhat is the difference between Git and GitHub?\nIs git saving every repository locally (in the user's machine) and in GitHub?\nCan you use Git without GitHub? If yes, what would be the benefit for using GitHub?\nHow does Git compare to a backup system such as Time Machine?\nIs this a manual process, in other words if you don't commit you wont have a new version of the changes made?\nIf are not collaborating and you are already using a backup system why would you use Git?" }, { "role": "assistant", "content": "What is the difference between Git and GitHub?\n\nGit is a version control system; think of it as a series of snapshots (commits) of your code. You see a path of these snapshots, in which order they where created. You can make branches to experiment and come back to snapshots you took.\nGitHub, is a web-page on which you can publish your Git repositories and collaborate with other people.\n\nIs Git saving every repository locally (in the user's machine) and in GitHub?\n\nNo, it's only local. You can decide to push (publish) some branches on GitHub.\n\nCan you use Git without GitHub? If yes, what would be the benefit for using GitHub?\n\nYes, Git runs local if you don't use GitHub. An alternative to using GitHub could be running Git on files hosted on Dropbox, but GitHub is a more streamlined service as it was made especially for Git.\n\nHow does Git compare to a backup system such as Time Machine?\n\nIt's a different thing, Git lets you track changes and your development process. If you use Git with GitHub, it becomes effectively a backup. However usually you would not push all the time to GitHub, at which point you do not have a full backup if things go wrong. \nI use git in a folder that is synchronized with Dropbox.\n\nIs this a manual process, in other words if you don't commit you won't have a new version of the changes made?\n\nYes, committing and pushing are both manual.\n\nIf are not collaborating and you are already using a backup system why would you use Git?\n\n\nIf you encounter an error between commits you can use the command git diff to see the differences between the current code and the last working commit, helping you to locate your error.\nYou can also just go back to the last working commit.\nIf you want to try a change, but are not sure that it will work. You create a branch to test you code change. If it works fine, you merge it to the main branch. If it does not you just throw the branch away and go back to the main branch.\nYou did some debugging. Before you commit you always look at the changes from the last commit. You see your debug print statement that you forgot to delete.\n\n\nMake sure you check gitimmersion.com." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options sendemail.forbidSendmailVariables" }, { "role": "assistant", "content": "To avoid common misconfiguration mistakes, git-send-email will abort with a warning if any configuration options for \"sendmail\"\nexist. Set this variable to bypass the check." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How do I revert a Git repository to a previous commit?\nThis question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.\n \n \n\n\n\n\n\n\nHow do I revert from my current state to a snapshot made on a certain commit?\nIf I do git log, then I get the following output:\n$ git log\ncommit a867b4af366350be2e7c21b8de9cc6504678a61b`\nAuthor: Me <[email protected]>\nDate: Thu Nov 4 18:59:41 2010 -0400\n\nblah blah blah...\n\ncommit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4\nAuthor: Me <[email protected]>\nDate: Thu Nov 4 05:13:39 2010 -0400\n\nmore blah blah blah...\n\ncommit 0766c053c0ea2035e90f504928f8df3c9363b8bd\nAuthor: Me <[email protected]>\nDate: Thu Nov 4 00:55:06 2010 -0400\n\nAnd yet more blah blah...\n\ncommit 0d1d7fc32e5a947fbd92ee598033d85bfc445a50\nAuthor: Me <[email protected]>\nDate: Wed Nov 3 23:56:08 2010 -0400\n\nYep, more blah blah.\n\nHow do I revert to the commit from November 3, i.e. commit 0d1d7fc?" }, { "role": "assistant", "content": "This depends a lot on what you mean by \"revert\".\nTemporarily switch to a different commit\nIf you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit:\n# This will detach your HEAD, that is, leave you with no branch checked out:\ngit checkout 0d1d7fc32\n\nOr if you want to make commits while you're there, go ahead and make a new branch while you're at it:\ngit checkout -b old-state 0d1d7fc32\n\nTo go back to where you were, just check out the branch you were on again. (If you've made changes, as always when switching branches, you'll have to deal with them as appropriate. You could reset to throw them away; you could stash, checkout, stash pop to take them with you; you could commit them to a branch there if you want a branch there.)\nHard delete unpublished commits\nIf, on the other hand, you want to really get rid of everything you've done since then, there are two possibilities. One, if you haven't published any of these commits, simply reset:\n# This will destroy any local modifications.\n# Don't do it if you have uncommitted work you want to keep.\ngit reset --hard 0d1d7fc32\n\n# Alternatively, if there's work to keep:\ngit stash\ngit reset --hard 0d1d7fc32\ngit stash pop\n# This saves the modifications, then reapplies that patch after resetting.\n# You could get merge conflicts, if you've modified things which were\n# changed since the commit you reset to.\n\nIf you mess up, you've already thrown away your local changes, but you can at least get back to where you were before by resetting again.\nUndo published commits with new commits\nOn the other hand, if you've published the work, you probably don't want to reset the branch, since that's effectively rewriting history. In that case, you could indeed revert the commits. In many enterprise organisations, the concept of \"protected\" branches will even prevent history from being rewritten on some major branches. In this case, reverting is your only option.\nWith Git, revert has a very specific meaning: create a commit with the reverse patch to cancel it out. This way you don't rewrite any history.\nFirst figure out what commits to revert. Depending on the technique chosen below, you want to either revert only the merge commits, or only the non-merge commits.\n# This lists all merge commits between 0d1d7fc and HEAD:\ngit log --merges --pretty=format:\"%h\" 0d1d7fc..HEAD | tr '\\n' ' '\n\n# This lists all non merge commits between 0d1d7fc and HEAD:\ngit log --no-merges --pretty=format:\"%h\" 0d1d7fc..HEAD | tr '\\n' ' '\n\nNote: if you revert multiple commits, the order matters. Start with the most recent commit.\n# This will create three separate revert commits, use non merge commits only:\ngit revert a867b4af 25eee4ca 0766c053\n\n# It also takes ranges. This will revert the last two commits:\ngit revert HEAD~2..HEAD\n\n# Similarly, you can revert a range of commits using commit hashes (non inclusive of first hash):\ngit revert 0d1d7fc..a867b4a\n\n# Reverting a merge commit. You can also use a range of merge commits here.\ngit revert -m 1 <merge_commit_sha>\n\n# To get just one, you could use `rebase -i` to squash them afterwards\n# Or, you could do it manually (be sure to do this at top level of the repo)\n# get your index and work tree into the desired state, without changing HEAD:\ngit checkout 0d1d7fc32 .\n\n# Then commit. Be sure and write a good message describing what you just did\ngit commit\n\nThe git-revert manpage actually covers a lot of this in its description. Another useful link is this git-scm.com section discussing git-revert.\nIf you decide you didn't want to revert after all, you can revert the revert (as described here) or reset back to before the revert (see the previous section).\nYou may also find this answer helpful in this case:\nHow can I move HEAD back to a previous location? (Detached head) & Undo commits" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git - the stupid content tracker --glob-pathspecs" }, { "role": "assistant", "content": "Add \"glob\" magic to all pathspec. This is equivalent to setting\nthe GIT_GLOB_PATHSPECS environment variable to 1 . Disabling\nglobbing on individual pathspecs can be done using pathspec\nmagic \":(literal)\"" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Log in to GitHub from the command line with multiple accounts\nI opened a new GitHub account to separate my business vs. personal repositories.\nNow, I git init my local repository and git add remote origin <the repository HTTPS URL>\nI try to push, and it seems to always take the credentials of my original account, not prompting me for the credentials for the new account.\nI tried using the URL format with\nhttps://<username>:<password>@github.com/<username>/<repository.git>\n\nbut that doesn't seem to help: I still get an error that the credentials are invalid for the original account username.\nHow do I log in with multiple sets of credentials or how would I somehow reset the original credentials to force password prompt when pushing?\n\nThe only way I managed to push right now is by specifying the username:[email protected]/ in the URL in the git push command." }, { "role": "assistant", "content": "git config --global credential.helper cache\n\n... which tells git to keep your password cached in memory for (by default) 15 minutes. You can set a longer timeout with:\ngit config --global credential.helper \"cache --timeout=3600\"\n\nMore useful links:\nhttps://confluence.atlassian.com/bitbucketserver/permanently-authenticating-with-git-repositories-776639846.html\n\nUsing the .netrc file\n The .netrc file is a mechanism that allows you to specify which credentials to use for which server. \nThis method allows you to avoid entering a username and password every time you push to or pull from Git, but your Git password is stored in plain text.\n\n\nYou can store your credentials using the following command\ngit config credential.helper store\ngit push http://example.com/repo.git\n# Now type username and password and it should be saved by git." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-tag - Create, list, delete or verify a tag object signed with GPG -u <key-id> --local-user=<key-id>" }, { "role": "assistant", "content": "Make a GPG-signed tag, using the given key." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Git branch diverged after rebase\nI have rebased a branch locally which was already pushed.\nGit is advising that my branch and remote have diverged and that:\n\"and have 109 and 73 different commits each, respectively\"\nWill pushing my branch resolve this - i.e. is this to be expected after a rebase?" }, { "role": "assistant", "content": "When you rebase a branch, you have to rewrite the commits for any commit which is above the commits in the branch onto which you are rebasing. This is because one of the properties of a commit is its parent (or parents). When you rebase, you're changing the parent of the oldest local commit on your branch - and thus changing the commit hashes of all of your local commits, since this change bubbles up through the commits transitively.\nSince you'd already pushed the branch, you should have merged in the source branch, rather than rebasing against it. It is possible to \"force push\" your new branch (using the -f flag), but a normal push won't work, because the integrity of the branches history will be disturbed. If you are collaborating with others on this branch, force pushing is a bad idea, as it will cause other collaborators to become very confused when their history suddenly doesn't match. \nTL;DR - If you're not collaborating, push the branch using push -f. If you are, reset the branch to the previous state, and merge in the source branch, instead." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-difftool - Show changes using common diff tools diff.guitool" }, { "role": "assistant", "content": "Controls which diff tool is used by git-difftool when\nthe -g/--gui flag is specified. This variable overrides the value\nconfigured in merge.guitool . The list below shows the valid\nbuilt-in values. Any other value is treated as a custom diff tool\nand requires that a corresponding difftool.<guitool>.cmd variable\nis defined." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to create patch between two tags with multiple commits between them?\nI have two tags in my git in same branch. There are at least 5-6 commits between them. How can I create a single patch between the two tags so that it can be applied to a GitHub repo?" }, { "role": "assistant", "content": "You can create a single diff (patch) between two tags using the following\n$ git diff tag1 tag2 -- > the-patch.diff\n\nReplace tag1 and tag2 to the tags you want." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git - the stupid content tracker git-name-rev" }, { "role": "assistant", "content": "Find symbolic names for given revs" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-diff - Show changes between commits, commit and working tree, etc --no-renames" }, { "role": "assistant", "content": "Turn off rename detection, even when the configuration\nfile gives the default to do so." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How do I 'overwrite', rather than 'merge', a branch on another branch in Git?\nI have two branches, email and staging. staging is the latest one and I no longer need the old changes in email branch, yet I don't want to delete them.\nSo I just want to dump all the contents of staging into email so that they both point to the same commit. Is that possible?" }, { "role": "assistant", "content": "You can use the 'ours' merge strategy:\n$ git checkout staging\n$ git merge -s ours email # Merge branches, but use our (=staging) branch head\n$ git checkout email\n$ git merge staging\n\n\nThe question requires the commits of the email branch to be kept. They must not be made unreachable, which rules out any reset-based approaches or deleting and recreating the branch.\n\nI no longer need the old changes in email branch, yet I don't want to delete them.\n\nTo keep commits of both branches reachable, one or more references must exist that point to those commits. You can always keep two references (staging and email), but the question asks to get rid of one of the refs. Therefore, the branches need to be merged somehow.\n\nEDIT 2020-07-30:\nI thought a bit more about this question and possible solutions. If you absolutely require the merge parents in the correct order, need to perform this action with a single command line invocation, and don't mind running plumbing commands, you can do the following:\n$ git checkout A\n$ git merge --ff-only $(git commit-tree -m \"Throw away branch 'A'\" -p A -p B B^{tree})\n\nThis basically acts like the (non-existent) merge -s theirs strategy.\nYou can find the resulting history in the plumbing branch of the demo repository\nNot very readable and not as easy to remember compared to the -s ours switch, but it does the job. The resulting tree is again the same as branch B:\n$ git rev-parse A^{tree} B^{tree} HEAD^{tree}\n3859ea064e85b2291d189e798bfa1bff87f51f3e\n0389f8f2a3e560b639d82597a7bc5489a4c96d44\n0389f8f2a3e560b639d82597a7bc5489a4c96d44\n\n\nEDIT 2020-07-29:\nThere seems to be a lot of confusion as to what the difference between -s ours and -X ours (the latter being equivalent to -s recursive --strategy-option ours) is. Here's a small example to show the two results from using these two methods. I also recommend reading the question and answers of (Git Merging) When to use 'ours' strategy, 'ours' option and 'theirs' option?\nFirst, setup a repository with 2 branches and 3 commits (1 base commit, and 1 commit per branch). You can find the sample repository on GitHub\n$ git init\n$ echo 'original' | tee file1 file2 file3\n$ git commit -m 'initial commit'\n$ git branch A\n$ git branch B\n$ git checkout A\n$ echo 'A' > file1\n$ git commit -m 'change on branch A' file1\n$ git checkout B\n$ echo 'B' > file2\n$ git commit -m 'change on branch B' file2\n\nNow, let's try the strategy option (doesn't really matter if we use theirs or ours for this explanation):\n$ git merge -X ours A\n$ cat file*\nA\nB\noriginal\n\nWe end up with a merge of both branches' contents (branch \"strategy-option\" in the sample repo). Compare that to using the merge strategy (re-init your repository or reset branch, before executing the next steps):\n$ git merge -s ours A\n$ cat file*\noriginal\nB\noriginal\n\nThe result is quite different (branch \"merge-strategy\" in the sample repo). With the strategy option, we get a merge result of both branches, with the strategy we throw away any changes which happened in the other branch.\nYou will also notice that the commit created by the merge-strategy in fact points to the exact same tree as the latest commit of \"our\" branch, while the strategy-option created a new, previously-unseen tree:\n$ git rev-parse A^{tree} B^{tree} merge-strategy^{tree} strategy-option^{tree}\n3859ea064e85b2291d189e798bfa1bff87f51f3e\n0389f8f2a3e560b639d82597a7bc5489a4c96d44\n0389f8f2a3e560b639d82597a7bc5489a4c96d44\n5b09d34a37a183723b409d25268c8cb4d073206e\n\nOP indeed asked for \"I no longer need the old changes in […] branch\" and \"So I just want to dump all the contents of [A] into [B]\", which is not possible to do with a strategy option. Using the 'ours' merge strategy is one possibility of many, but likely the easiest (other possibilities include using low level commands of Git such as write-tree and commit-tree)." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Errno::EACCES: Permission denied when installing gems via gitlab\n\nI'm trying to setup gitlab and thus install some gems from another user account using sudo,\nbut I'm constantly getting Permission denied error.\nsudo -u gitlab -H bundle install --deployment --without development test postgres\n\n> Using ... ( a lot of successful gems there )\n> Using pygments.rb (0.3.2) from https://github.com/gitlabhq/pygments.rb.git (at master) \n> Errno::EACCES: Permission denied - pygments.rb-0.3.2.gem\n> An error occurred while installing pygments.rb (0.3.2), and Bundler cannot continue.\n> Make sure that `gem install pygments.rb -v '0.3.2'` succeeds before bundling.\\\n\n\n\nsudo -u gitlab -H gem install pygments.rb -v '0.3.2'\n\n> Successfully installed pygments.rb-0.3.2\n> 1 gem installed\n> Installing ri documentation for pygments.rb-0.3.2...\n> Installing RDoc documentation for pygments.rb-0.3.2...\n# no matter how many times I run this command, I always get the same output\n# as if the gem installation doesn't stick \n\n\n# I've tried to chmod\nchmod 777 -R /usr/local/lib/ruby\n\n\n\n# then Again\nsudo -u gitlab -H bundle install --deployment --without development test postgres\n# same result, Errno::EACCES: Permission denied - pygments.rb-0.3.2.gem" }, { "role": "assistant", "content": "Lain suggested to try to install the bundles into another sub directory. When that worked out, it became clear the problem was about permissions in the current directory.\nExecuting chown -R gitlab:gitlab . has solved the problem. \nIn the gitlab installation guide there is a gem install command preceding our story that was ran as root and probably the gemfile or some other file had permissions change during that." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "gitfaq - Frequently asked questions about using Git If I make a change on two branches but revert it on one, why does the merge of those branches include the change?" }, { "role": "assistant", "content": "By default, when Git does a merge, it uses a strategy called the ort strategy, which does a fancy three-way merge. In such a case, when Git\nperforms the merge, it considers exactly three points: the two heads and a\nthird point, called the merge base , which is usually the common ancestor of\nthose commits. Git does not consider the history or the individual commits\nthat have happened on those branches at all. As a result, if both sides have a change and one side has reverted that change,\nthe result is to include the change. This is because the code has changed on\none side and there is no net change on the other, and in this scenario, Git\nadopts the change. If this is a problem for you, you can do a rebase instead, rebasing the branch\nwith the revert onto the other branch. A rebase in this scenario will revert\nthe change, because a rebase applies each individual commit, including the\nrevert. Note that rebases rewrite history, so you should avoid rebasing\npublished branches unless you’re sure you’re comfortable with that. See the\nNOTES section in git-rebase for more details." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options amWorkDir" }, { "role": "assistant", "content": "Shown when git-am fails to apply a patch\nfile, to tell the user the location of the file." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "\"git pull --rebase\" leads to \"Cannot rebase onto multiple branches\"\n\nSo, my work environment has precisely one branch with a remote companion on Github. I'm trying to do git pull --rebase in order to prevent git push from creating merge commit messages that don't provide new information to others working on this project and just gum up the works. But when I try that, it gives me this:\nFrom https://github.com/our_profile/our_repository\n * branch HEAD -> FETCH_HEAD\nCannot rebase onto multiple branches\n\nAnd the pull aborts. Calling git branch informs me that I have only one branch on my local machine, so what's going on?" }, { "role": "assistant", "content": "Try specifying exactly what remote branch you want to pull:\ngit pull --rebase origin branch\n\nAlternatively you can also git fetch all changes from the remote repository first, and then rebase manually:\ngit rebase origin/branch" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Get latest tag in .gitlab-ci.yml for Docker build\n\nI want to add a tag when building a Docker image, I'm doing this so far but I do not know how to get the latest tag on the repository being deployed.\ndocker build -t company/app .\n\nMy goal\ndocker build -t company/app:$LATEST_TAG_IN_REPO? ." }, { "role": "assistant", "content": "Since you're looking for the \"latest\" git tag which is an ancestor of the currently building commit you probably want to use\ngit describe --tags --abbrev=0\n\nto get it and use it like:\ndocker build -t company/app:$(git describe --tags --abbrev=0) .\n\nRead here for the finer points on git describe" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-clean - Remove untracked files from the working tree select by numbers" }, { "role": "assistant", "content": "This shows the files and directories to be deleted and issues an\n\"Select items to delete>>\" prompt. When the prompt ends with double >> like this, you can make more than one selection, concatenated\nwith whitespace or comma. Also you can say ranges. E.g. \"2-5 7,9\"\nto choose 2,3,4,5,7,9 from the list. If the second number in a\nrange is omitted, all remaining items are selected. E.g. \"7-\" to\nchoose 7,8,9 from the list. You can say * to choose everything.\nAlso when you are satisfied with the filtered result, press ENTER\n(empty) back to the main menu." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "gitrevisions - Specifying revisions and ranges for Git <rev>^@ , e.g. HEAD^@" }, { "role": "assistant", "content": "A suffix ^ followed by an at sign is the same as listing\nall parents of <rev> (meaning, include anything reachable from\nits parents, but not the commit itself)." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to show uncommitted changes in Git and some Git diffs in detail\nHow do I show uncommitted changes in Git?\nI STFW'ed, and these commands are not working:\nteyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)\n$ git status\nOn branch teyan/psservice\nYour branch is up-to-date with 'origin/teyan/psservice'.\nChanges to be committed:\n (use \"git reset HEAD <file>...\" to unstage)\n\n modified: psservice.c\n modified: psservice.vcxproj.filters\n\n\nteyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)\n$ git diff\n\nteyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)\n$ git diff master\nfatal: ambiguous argument 'master': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'" }, { "role": "assistant", "content": "How to show uncommitted changes in Git\n\nThe command you are looking for is git diff.\n\ngit diff - Show changes between commits, commit and working tree, etc\n\n\nHere are some of the options it expose which you can use\ngit diff (no parameters)\nPrint out differences between your working directory and the index.\ngit diff --cached:\nPrint out differences between the index and HEAD (current commit).\ngit diff HEAD:\nPrint out differences between your working directory and the HEAD.\ngit diff --name-only\nShow only names of changed files.\ngit diff --name-status\nShow only names and status of changed files.\ngit diff --color-words\nWord by word diff instead of line by line.\nHere is a sample of the output for git diff --color-words:" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Pushing code from one branch of a repo to another branch of another repo\n\nThere is a repo say ABC/A. I had forked this repo to my own github say ME/A. I was asked to create a branch on ME/A say x (originally there were develop and master). I had to write some code, so I cloned ABC/A and worked on its develop branch. But now when I have to push the code, I cannot push it to ABC/A as i dont have rights to do so. I have to push the code to ME/A. The problem is, I worked on develop branch for ABC/A but I have to push the code to ME/A x branch. Is it possible to push code in such a way?" }, { "role": "assistant", "content": "Yes, you can push any local branch to any remote branch. The syntax is\ngit push <remote name, e.g. origin> <local branch name>:<remote branch name>\n\nIf your current branch (the one you want to push) is called develop, the command would be\ngit push ME develop:x" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "gitglossary - A Git Glossary overlay" }, { "role": "assistant", "content": "Only update and add files to the working directory, but don’t\ndelete them, similar to how cp -R would update the contents\nin the destination directory. This is the default mode in a checkout when checking out files from the index or a tree-ish . In\ncontrast, no-overlay mode also deletes tracked files not\npresent in the source, similar to rsync --delete ." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "What is git tag, How to create tags & How to checkout git remote tag(s)\nwhen I checkout remote git tag use command like this:\ngit checkout -b local_branch_name origin/remote_tag_name\n\nI got error like this:\n\nerror: pathspec origin/remote_tag_name did not match any file(s) known to git.\n\nI can find remote_tag_name when I use git tag command." }, { "role": "assistant", "content": "Let's start by explaining what a tag in git is\n\n\nA tag is used to label and mark a specific commit in the history.\nIt is usually used to mark release points (eg. v1.0, etc.).\n\n\nAlthough a tag may appear similar to a branch, a tag, however, does not change. It points directly to a specific commit in the history and will not change unless explicitly updated.\n\n\n\nYou will not be able to checkout the tags if it's not locally in your repository so first, you have to fetch the tags to your local repository.\nFirst, make sure that the tag exists locally by doing\n# --all will fetch all the remotes.\n# --tags will fetch all tags as well\n$ git fetch --all --tags --prune\n\nThen check out the tag by running\n$ git checkout tags/<tag_name> -b <branch_name>\n\nInstead of origin use the tags/ prefix.\n\nIn this sample you have 2 tags version 1.0 & version 1.1 you can check them out with any of the following:\n$ git checkout A ...\n$ git checkout version 1.0 ...\n$ git checkout tags/version 1.0 ...\n\nAll of the above will do the same since the tag is only a pointer to a given commit.\n\norigin: https://backlog.com/git-tutorial/img/post/stepup/capture_stepup4_1_1.png\n\nHow to see the list of all tags?\n# list all tags\n$ git tag\n\n# list all tags with given pattern ex: v-\n$ git tag --list 'v-*'\n\n\nHow to create tags?\nThere are 2 ways to create a tag:\n# lightweight tag \n$ git tag v1.0\n\n# annotated tag\n$ git tag -a v1.0\n\nThe difference between the 2 is that when creating an annotated tag you can add metadata as you have in a git commit:\nname, e-mail, date, comment & signature\n\nHow to delete tags?\nDelete a local tag\n$ git tag -d <tag_name>\nDeleted tag <tag_name> (was 000000)\n\nNote: If you try to delete a non existig Git tag, there will be see the following error:\n$ git tag -d <tag_name>\nerror: tag '<tag_name>' not found.\n\nDelete remote tags\n# Delete a tag from the server with push tags\n$ git push --delete origin <tag name>\n\nHow to clone a specific tag?\nIn order to grab the content of a given tag, you can use the checkout command. As explained above tags are like any other commits so we can use checkout and instead of using the SHA-1 simply replacing it with the tag_name\nOption 1:\n# Update the local git repo with the latest tags from all remotes\n$ git fetch --all\n\n# checkout the specific tag\n$ git checkout tags/<tag> -b <branch>\n\nOption 2:\nUsing the clone command\nSince git supports shallow clone by adding the --branch to the clone command we can use the tag name instead of the branch name. Git knows how to \"translate\" the given SHA-1 to the relevant commit\n# Clone a specific tag name using git clone \n$ git clone <url> --branch=<tag_name>\n\n\ngit clone --branch=\n--branch can also take tags and detaches the HEAD at that commit in the resulting repository.\n\n\nHow to push tags?\ngit push --tags\nTo push all tags:\n# Push all tags\n$ git push --tags \n\nUsing the refs/tags instead of just specifying the <tagname>.\nWhy?\n\nIt's recommended to use refs/tags since sometimes tags can have the same name as your branches and a simple git push will push the branch instead of the tag\n\nTo push annotated tags and current history chain tags use:\ngit push --follow-tags\nThis flag --follow-tags pushes both commits and only tags that are both:\n\nAnnotated tags (so you can skip local/temp build tags)\nReachable tags (an ancestor) from the current branch (located on the history)\n\n\nFrom Git 2.4 you can set it using configuration\n$ git config --global push.followTags true\n\n\nCheatsheet:" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Git core.autocrlf line ending default setting\nI'm trying to figure out what is the default value for core.autocrlf in Git if the user doesn't change this setting.\nI've looked in the docs but can't find this info. Can you please point me in the right direction?\nSpecifically, on a fresh Git install, would Git automatically convert Windows line endings to Unix when committing to a repo from a Windows system?\nThanks!" }, { "role": "assistant", "content": "Checking the git source code, core.autocrlf is set to false by default. (And has been since the property's original introduction on Feb 13, 2007, though it has since been converted from a static value to a constant.)\nThe Windows installer does require you to pick a value for this property which is explicitly set in the git system config." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Writing a git post-receive hook to deal with a specific branch\nHere's my current hook in a bare repo that lives in the company's server:\ngit push origin master\nThis hooks pushes to Assembla.\nWhat i need is to push only one branch (master, ideally) when someone pushes changes to that branch on our server, and ignore pushes to other branches. Is it possible to select the branch from a bare repo and push only that branch to Assembla?" }, { "role": "assistant", "content": "A post-receive hook gets its arguments from stdin, in the form:\n<oldrev> <newrev> <refname>\n\nSince these arguments are coming from stdin, not from a command line argument, you need to use read instead of $1 $2 $3.\nThe post-receive hook can receive multiple branches at once (for example if someone does a git push --all), so we also need to wrap the read in a while loop.\nA working snippet looks something like this:\n#!/bin/bash\nwhile read oldrev newrev refname\ndo\n branch=$(git rev-parse --symbolic --abbrev-ref $refname)\n if [ \"master\" = \"$branch\" ]; then\n # Do something\n fi\ndone" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Proper way to fix potential security vulnerability in a dependency defined in package-lock.json\n\nGithub has given me this error on one of my repositories.\nWe found a potential security vulnerability in one of your dependencies.\nA dependency defined in ./package-lock.json has known security vulnerabilities \nand should be updated.\n\nThe dependency is not defined in our package.json file. To my understanding it isn't good practice to delete the package-lock.json file and regenerate it. However, I cannot see any other way to fix this issue. If I dismiss this security vulnerability it will appear again a couple of days later. Any ideas? Thanks!" }, { "role": "assistant", "content": "New: now, with npm@6 you can directly run\nnpm audit fix\n\n\nOld answer:\nYou should try to identify the problematic package's name, and then run\nnpm install package-name\n\nreplacing package-name, obviously.\nThis will install the latest version of the package, and very often, the latest version has fixed the security issue. If you have a constraint on version (eg: 1.2), you can always try to:\nnpm install package-name@^1.2\n\nand the latest patched version will be installed" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-rev-parse - Pick out and massage parameters <refname> , e.g. master , heads/master , refs/heads/master" }, { "role": "assistant", "content": "A symbolic ref name. E.g. master typically means the commit\nobject referenced by refs/heads/master . If you\nhappen to have both heads/master and tags/master , you can\nexplicitly say heads/master to tell Git which one you mean.\nWhen ambiguous, a <refname> is disambiguated by taking the\nfirst match in the following rules: If $GIT_DIR/<refname> exists, that is what you mean (this is usually\nuseful only for HEAD , FETCH_HEAD , ORIG_HEAD , MERGE_HEAD , REBASE_HEAD , REVERT_HEAD , CHERRY_PICK_HEAD , BISECT_HEAD and AUTO_MERGE ); otherwise, refs/<refname> if it exists; otherwise, refs/tags/<refname> if it exists; otherwise, refs/heads/<refname> if it exists; otherwise, refs/remotes/<refname> if it exists; otherwise, refs/remotes/<refname>/HEAD if it exists. HEAD names the commit on which you based the changes in the working tree. FETCH_HEAD records the branch which you fetched from a remote repository with\nyour last git fetch invocation. ORIG_HEAD is created by commands that move your HEAD in a drastic way ( git\nam , git merge , git rebase , git reset ), to record the position\nof the HEAD before their operation, so that you can easily change\nthe tip of the branch back to the state before you ran them. MERGE_HEAD records the commit(s) which you are merging into your branch when you\nrun git merge . REBASE_HEAD during a rebase, records the commit at which the operation is\ncurrently stopped, either because of conflicts or an edit command in\nan interactive rebase. REVERT_HEAD records the commit which you are reverting when you run git revert . CHERRY_PICK_HEAD records the commit which you are cherry-picking when you run git\ncherry-pick . BISECT_HEAD records the current commit to be tested when you run git bisect\n--no-checkout . AUTO_MERGE records a tree object corresponding to the state the ort merge strategy wrote to the working tree when a merge operation\nresulted in conflicts. Note that any of the refs/* cases above may come either from\nthe $GIT_DIR/refs directory or from the $GIT_DIR/packed-refs file.\nWhile the ref name encoding is unspecified, UTF-8 is preferred as\nsome output processing may assume ref names in UTF-8." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "gitglossary - A Git Glossary branch" }, { "role": "assistant", "content": "A \"branch\" is a line of development. The most recent commit on a branch is referred to as the tip of\nthat branch. The tip of the branch is referenced by a branch head , which moves forward as additional development\nis done on the branch. A single Git repository can track an arbitrary number of\nbranches, but your working tree is\nassociated with just one of them (the \"current\" or \"checked out\"\nbranch), and HEAD points to that branch." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to download a branch with git?\nI have a project hosted on GitHub. I created a branch on one computer, then pushed my changes to GitHub with: \ngit push origin branch-name\n\nNow I am on a different computer, and I want to download that branch. So I tried:\ngit pull origin branch-name\n\n...but all this did was overwrite my master branch with the changes in my new branch.\nWhat do I need to do to properly pull my remote branch, without overwriting existing branches?" }, { "role": "assistant", "content": "Thanks to a related question, I found out that I need to \"checkout\" the remote branch as a new local branch, and specify a new local branch name.\ngit checkout -b newlocalbranchname origin/branch-name\n\nOr you can do:\ngit checkout -t origin/branch-name\n\nThe latter will create a branch that is also set to track the remote branch.\n\nUpdate: It's been 5 years since I originally posted this question. I've learned a lot and git has improved since then. My usual workflow is a little different now.\nIf I want to fetch the remote branches, I simply run:\ngit pull\n\nThis will fetch all of the remote branches and merge the current branch. It will display an output that looks something like this:\nFrom github.com:andrewhavens/example-project\n dbd07ad..4316d29 master -> origin/master\n * [new branch] production -> origin/production\n * [new branch] my-bugfix-branch -> origin/my-bugfix-branch\nFirst, rewinding head to replay your work on top of it...\nFast-forwarded master to 4316d296c55ac2e13992a22161fc327944bcf5b8.\n\nNow git knows about my new my-bugfix-branch. To switch to this branch, I can simply run:\ngit checkout my-bugfix-branch\n\nNormally, I would need to create the branch before I could check it out, but in newer versions of git, it's smart enough to know that you want to checkout a local copy of this remote branch." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Change GIT account of Visual Studio Team Explorer\nI am having a very weird situation when cloning a Git repository from our company private server. The repository is not anonymous (it requires authentication), but when cloning, VS didn't ask any username and password and automatically use an old authentication of old employee. Is there a way to remove the saved username and password and make Visual Studio to prompt them when cloning?" }, { "role": "assistant", "content": "Look in the Windows Credential manager and remove/update your credentials there:" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-notes - Add or inspect object notes" }, { "role": "assistant", "content": "SYNOPSIS git notes [list [<object>]] git notes add [-f] [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] git notes copy [-f] ( --stdin | <from-object> [<to-object>] ) git notes append [--allow-empty] [--[no-]separator | --separator=<paragraph-break>] [--[no-]stripspace] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>] git notes edit [--allow-empty] [<object>] [--[no-]stripspace] git notes show [<object>] git notes merge [-v | -q] [-s <strategy> ] <notes-ref> git notes merge --commit [-v | -q] git notes merge --abort [-v | -q] git notes remove [--ignore-missing] [--stdin] [<object>…​] git notes prune [-n] [-v] git notes get-ref" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Eclipse + EGit: clone project into workspace\n\nI'm a little confused about how EGit workes.\nI have an existing git repository on Github and want to clone it into my workspace. \nMy goal is to have the local repository directly stored inside my workspace-folder but I don't get it working with EGit.\nWhen I want to clone the github repo with EGit, I have to choose a directory as destination. The suggested directory is in my homedir (not in my workspace). When I choose this directory I can see the project in Eclipse but it is not stored in my workspace-folder. Instead it is stored in my home dir. \nWhen I choose a directory directly inside my workspace, later when it comes to import the project it says that there is already a directory with this name. \nI don't know how to solve this. I thought this would be a common scenario. In the past I have used hgEclipse (Mercurial) and it was working exactly the way I thought it should be so I'm confused EGit doesn't. Maybe I misunderstood something.\nProbably this is important to know: In the github repository there are no .project or .settings files from eclipse. I have them on my .gitignore and so in the import-dialog I have to choose \"Import as General Project\" and not \"Import Existing Projects\". But I think this shouldn't matter?\nI hope someone can help me or explain me why the EGit plugin doesn't clone the repository directly into the workspace by default. \nMy Eclipseversion is 3.6, I have installed EGit over the markedplace." }, { "role": "assistant", "content": "As mentioned in this EGit tutorial, the destination directory you mention when importing (cloning) a Git repo is any directory you want, in which the .git will be created:\n\nYou don't have to select the workspace itself (at least, you should select the workspace/myproject subdirectory, in order to not make the all Eclipse workspace a Git repo.\nAnd you can select any other directory outside the workspace: the Eclipse workspace should only contain meta-data about Eclipse projects and settings.\nWhen declaring a new project, you will be able to select the project directory, making that directory the parent for .classpath and .project.\nYour workspace will list that new project, even though it lives outside the workspace." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Git: ignore some files during a merge (keep some files restricted to one branch)\nI have two branches, A and B. Branch A have a directory examples with some files that are tracked by git, and these files should not appear on branch B. In my workflow, I do merge changes made in A into B often, which is a problem every time that there is some changes on examples. For the moment I am doing this manually: erasing the files after the merge or solving conflicts when there was a change to a file that I had already erased.\nIs it possible to ignore these files during a merge? (Or is it possible to keep some files restricted to one branch (A) or away from one branch (B)?)\n\nLet me try to explain why I am doing this:\nA is a skeleton of a blog (template, scripts, etc), B is my blog (A filled with my own posts, images, drafts, etc). A is public and I am trying to make it generic to others look and use it, but because of this I need some posts there as a showcase/tests (the examples directory). Every change in A and is later merged into B to have this changes on my blog instance -- this way all new examples appear in B and all deleted examples in B that have been changed in A since last merge results in a conflict." }, { "role": "assistant", "content": "I found a good answer here: stackoverflow Q332528\nIt uses ideas taken from here: Pro-Git merge strategies\nHere is a copy of it:\n\nLet's say you want to exclude the file config.php\nOn branch A:\n\nCreate a file named '.gitattributes' in the same dir, with this\nline: config.php merge=ours. This tells git what strategy to use\nwhen mergin the file. In this case it always keep your version, ie.\nthe version on the branch you are merging into.\n\nAdd the .gitattributes file and commit\n\n\nOn branch B: repeat steps 1-2\nTry merging now. Your file should be left untouched.\n\n\nEdit:\nFrom the git book regarding merge=ours, \"One very useful option is to tell Git to not try to merge specific files when they have conflicts, but rather to use your side of the merge over someone else’s.\"\nSo, this answer doesn't apply as well as it might to the question. pjmorse's answer regarding using submodules is good.\nAnother option would be to use a sub-tree merge, which may have added benefits." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How do I ignore files in a directory in Git?\nWhat is the proper syntax for the .gitignore file to ignore files in a directory?\nWould it be\nconfig/databases.yml\ncache/*\nlog/*\ndata/sql/*\nlib/filter/base/*\nlib/form/base/*\nlib/model/map/*\nlib/model/om/*\n\nor\n/config/databases.yml\n/cache/*\n/log/*\n/data/sql/*\n/lib/filter/base/*\n/lib/form/base/*\n/lib/model/map/*\n/lib/model/om/*\n\n?" }, { "role": "assistant", "content": "PATTERN FORMAT\n\nA blank line matches no files, so it can serve as a separator for readability.\nA line starting with # serves as a comment.\nAn optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.\nIf the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git).\nIf the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).\nOtherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, Documentation/*.html matches Documentation/git.html but not Documentation/ppc/ppc.html or tools/perf/Documentation/perf.html.\nA leading slash matches the beginning of the pathname. For example, /*.c matches cat-file.c but not mozilla-sha1/sha1.c.\n\nYou can find more here\ngit help gitignore\nor\nman gitignore" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-rev-list - Lists commit objects in reverse chronological order -i --regexp-ignore-case" }, { "role": "assistant", "content": "Match the regular expression limiting patterns without regard to letter\ncase." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options gui.commitMsgWidth" }, { "role": "assistant", "content": "Defines how wide the commit message window is in the git-gui . \"75\" is the default." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Gitlabs artifact of one project used in further projects\n\nQuestion\n\nWhat is the best way to carry artifacts (jar, class, war) among projects when using docker containers in CI phase.\n\nLet me explain my issue in details, please don't stop the reading... =)\nGitlabs project1\n\nunit tests\netc...\npackage\n\nGitlabs project2\n\nunit test\netc...\nbuild (failing)\n\n\nhere I need one artifact (jar) generated in project1\n\n\nCurrent scenario / comments\n\nI'm using dockers so in each .gitlab-ci.yml I'll have independent containers\nAll is working fine in project1\nIf I use \"shell\" instead of dockers in my .gitlab-ci.yml I can keep the jar file from the project1 in the disk and use when project2 kicks the build\nToday my trigger on call project2 when project1 finish is working nicely\nMy artifact is not an RPM so I'll not add into my repo\n\nPossible solutions\n\nI can commit the artifact of project1 and checkout when need to build project2\nI need to study if cache feature from gitlabs is designed for this purpose (gitlab 8.2.1, How to use cache in .gitlab-ci.yml)" }, { "role": "assistant", "content": "In GitLab silver and premium, there is the\n$CI_JOB_TOKEN available, which allows the following .gitlab-ci.yaml snippet:\nbuild_submodule:\n image: debian\n stage: test\n script:\n - apt update && apt install -y unzip\n - curl --location --output artifacts.zip \"https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/master/download?job=test&job_token=$CI_JOB_TOKEN\"\n - unzip artifacts.zip\n only:\n - tags\n\nHowever, if you do not have silver or higher gitlab subscriptions, but rely on free tiers, it is also possible to use the API and pipeline triggers.\nLet's assume we have project A building app.jar which is needed by project B.\nFirst, you will need an API Token.\nGo to Profile settings/Access Tokens page to create one, then store it as a variable in project B. In my example it's GITLAB_API_TOKEN.\nIn the CI / CD settings of project B add a new trigger, for example \"Project A built\". This will give you a token which you can copy.\nOpen project A's .gitlab-ci.yaml and copy the trigger_build: section from project B's CI / CD settings trigger section.\nProject A:\ntrigger_build:\n stage: deploy\n script:\n - \"curl -X POST -F token=TOKEN -F ref=REF_NAME https://gitlab.example.com/api/v4/projects/${PROJECT_B_ID}/trigger/pipeline\"\n\nReplace TOKEN with that token (better, store it as a variable in project A -- then you will need to make it token=${TRIGGER_TOKEN_PROJECT_B} or something), and replace REF_NAME with your branch (e.g. master).\nThen, in project B, we can write a section which only builds on triggers and retrieves the artifacts.\nProject B:\ndownload:\n stage: deploy\n only:\n - triggers\n script:\n - \"curl -O --header 'PRIVATE-TOKEN: ${GITLAB_API_TOKEN}' https://gitlab.example.com/api/v4/projects/${PROJECT_A_ID}/jobs/${REMOTE_JOB_ID}/artifacts/${REMOTE_FILENAME}\"\n\nIf you know the artifact path, then you can replace ${REMOTE_FILENAME} with it, for example build/app.jar. The project ID can be found in the CI / CD settings.\nI extended the script in project A to pass the remaining information as documented in the trigger settings section:\n\nAdd variables[VARIABLE]=VALUE to an API request. Variable values can be used to distinguish between triggered pipelines and normal pipelines.\n\nSo the trigger passes the REMOTE_JOB_ID and the REMOTE_FILENAME, but of course you can modify this as you need it:\ncurl -X POST \\\n -F token=TOKEN \\\n -F ref=REF_NAME \\\n -F \"variables[REMOTE_FILENAME]=build/app.jar\" \\\n -F \"variables[REMOTE_JOB_ID]=${CI_JOB_ID}\" \\\n https://gitlab.example.com/api/v4/projects/${PROJECT_B_ID}/trigger/pipeline" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-cat-file - Provide contents or details of repository objects -p" }, { "role": "assistant", "content": "Pretty-print the contents of <object> based on its type." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-merge - Join two or more development histories together --quit" }, { "role": "assistant", "content": "Forget about the current merge in progress. Leave the index\nand the working tree as-is. If MERGE_AUTOSTASH is present, the\nstash entry will be saved to the stash list." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options http.delegation" }, { "role": "assistant", "content": "Control GSSAPI credential delegation. The delegation is disabled\nby default in libcurl since version 7.21.7. Set parameter to tell\nthe server what it is allowed to delegate when it comes to user\ncredentials. Used with GSS/kerberos. Possible values are: none - Don’t allow any delegation. policy - Delegates if and only if the OK-AS-DELEGATE flag is set in the\nKerberos service ticket, which is a matter of realm policy. always - Unconditionally allow the server to delegate." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "On building jenkins project timeout after 10 minute error happens\nI am using jenkins to build my git remote project. The problem is log says 'timeout after 10 min'. Receiving object starts and at 56% something happens." }, { "role": "assistant", "content": "Edit your job configuration, and under git plugin section:\n\nClick \"Add\"\nClick \"Advanced clone behaviours\"\nSet the number of minutes you want in \"Timeout (in minutes) for clone and fetch operation\"\n\nI recommend checking also the \"shallow clone\" option. It fetches only the last state of the repository (without the history), so it's much faster." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How do I force git pull to overwrite everything on every pull?\nI have a CENTRAL bare repository that has three developer repositories pulling and pushing to it normally.\nI also have two other repositories that pull from the CENTRAL bare repo: one is the live server, and the other is a test/stage server—each pulling from its own respective branch.\nThe scenario is this: I have a post-update hook script on the CENTRAL repo that automatically accesses the test and live repos and runs a pull command on each. This updates both test and live servers, all depending on what branch has new commits. This all works great.\nThe problem is this: there may be times in an emergency that files may be directly updated on the server (via ftp or whatever) and the CENTRAL post-update script will then fail since merge/overwrite conflicts will occur. There is no way to avoid this scenario, and it is inevitable.\nWhat I would like to have happen is this: I want the pull from the live and test sites to always overwrite/merge on pull. Always. These repos will be pull-only as they are not for development.\nIn all my research, I cannot find a good solution to have a pull always force an overwrite of the local files. Is this at all possible? It would make for a great development scenario if so." }, { "role": "assistant", "content": "Really the ideal way to do this is to not use pull at all, but instead fetch and reset:\ngit fetch origin master\ngit reset --hard FETCH_HEAD\ngit clean -df\n\n(Altering master to whatever branch you want to be following.)\npull is designed around merging changes together in some way, whereas reset is designed around simply making your local copy match a specific commit.\nYou may want to consider slightly different options to clean depending on your system's needs." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Migrating from TFS to Git\nIs it possible to migrate from TFS 2008 to Git, and still preserve all the history, etc?\nI've seen some references that talk about doing it through SVN, but that seems rather complicated, and complicates my mission to introduce Git at my job." }, { "role": "assistant", "content": "There is a direct way its called git-tfs and it's up on github.\nYou just do a \n git tfs clone <tfs server> <tfs project>\n\nI recommend getting the source and adding it to your path separately so that you can debug it for any strangeness, but the code is pretty easy to step through.\nI had a file that was an msi that was 500 MB that the client stored in tfs, that wouldn't convert, took a few hours to narrow it down." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git - the stupid content tracker gitprotocol-capabilities" }, { "role": "assistant", "content": "Protocol v0 and v1 capabilities" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Git - The revocation function was unable to check revocation for the certificate\n\nI'm trying to clone from Github by using both Github Desktop and the git shell but keep on getting this error:\nCloning into 'C:\\Users\\John Doe\\workspace\\MyProject'...\nfatal: unable to access 'https://github.com/JohnDoe/MyProject.git/': \nschannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - \nThe revocation function was unable to check revocation for the certificate.\n\nSame problem when pulling an existing repository.\nI've already tried to upload SSH keys found in ~/.ssh/github-ssh.pub to Github settings but it doesn't help anything.\nEDIT: Just checked, it will happen even if I try to clone a non-existent repository." }, { "role": "assistant", "content": "This error is also commonly hit when you're on a corporate network that performs MITM on all traffic, and then blocks the revocation check.\nWhile, obviously, the ideal situation is to not block the checks (or at least, to a whitelist of urls), it may be required to work around this problem.\nOne option is, as in the first part of Mike's answer, using the OpenSSL bindings instead. While this works, it requires manual maintenance of the certificate lists, which may not be practical in extreme situations (say, new root certs issued every day, although this is unlikely).\nThe other option, akin to the second part of Mike's answer, is disabling revocation checking.\nRecent versions, 2.19 and above, of git-for-windows provides an http.schannelCheckRevoke setting: \n\nUsed to enforce or disable certificate revocation checks in cURL\n when http.sslBackend is set to \"schannel\". Defaults to true if\n unset. Only necessary to disable this if Git consistently errors\n and the message is about checking the revocation status of a\n certificate. This option is ignored if cURL lacks support for\n setting the relevant SSL option at runtime.\n\n... so you can simply disable checking for revocation in the first place:\ngit config --global http.schannelCheckRevoke false\nNote that, unlike disabling SSL entirely, this is not inherently less secure than using Mike's answer for specific repositories: if you capture and configure an empty revocation list (the usual case), you have effectively disabled revocation checking. Disabling revocation checking only becomes a risk in the case of private-key compromise (at some point in the chain), which is rare and difficult. \nNote, also, that in a corporate MITM setting, revocation checking is being performed for you: no proxy worth using would issue a cert for an invalid or (known) compromised certificate." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options core.untrackedCache" }, { "role": "assistant", "content": "Determines what to do about the untracked cache feature of the\nindex. It will be kept, if this variable is unset or set to keep . It will automatically be added if set to true . And\nit will automatically be removed, if set to false . Before\nsetting it to true , you should check that mtime is working\nproperly on your system.\nSee git-update-index . keep by default, unless feature.manyFiles is enabled which sets this setting to true by default." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-notes - Add or inspect object notes --ref <ref>" }, { "role": "assistant", "content": "Manipulate the notes tree in <ref>. This overrides GIT_NOTES_REF and the \"core.notesRef\" configuration. The ref\nspecifies the full refname when it begins with refs/notes/ ; when it\nbegins with notes/ , refs/ and otherwise refs/notes/ is prefixed\nto form a full name of the ref." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Github - unexpected disconnect while reading sideband packet\nI've got quite interesting problem.\nI tried to send some projects via bash to repo and recently there was a problem with sending it.\nEnumerating objects: 27, done.\nCounting objects: 100% (27/27), done.\nDelta compression using up to 16 threads\nCompressing objects: 100% (24/24), done.\nWriting objects: 100% (25/25), 187.79 KiB | 9.39 MiB/s, done.\nTotal 25 (delta 1), reused 0 (delta 0), pack-reused 0\nsend-pack: unexpected disconnect while reading sideband packet\nfatal: the remote end hung up unexpectedly\n\nThe funny part is that 10 min earlier I can send it without any problems.\nI tried with getting new repo, creating new file, reinstalling git, git config --global http.postBuffer 524288000 with bigger numbers as well, also https.postBuffer and so on. Also install desktop version the same issue come in.\nI've got problems mostly with React apps.\nAnyone know the solution ? What could go wrong ?" }, { "role": "assistant", "content": "First of all, check your network connection stability.\nIf there is no problem with network connection try another solution; it may work:\nOn Linux\nExecute the following in the command line before executing the Git command:\nexport GIT_TRACE_PACKET=1\nexport GIT_TRACE=1\nexport GIT_CURL_VERBOSE=1\n\nOn Windows\nExecute the following in the command line before executing the Git command:\nset GIT_TRACE_PACKET=1\nset GIT_TRACE=1\nset GIT_CURL_VERBOSE=1\n\nIn addition:\ngit config --global core.compression 0\ngit clone --depth 1 <repo_URI>\n# cd to your newly created directory\ngit fetch --unshallow \ngit pull --all\n\nFor PowerShell users:\nAs kodybrown said in comments:\n$env:GIT_TRACE_PACKET=1\n$env:GIT_TRACE=1\n$env:GIT_CURL_VERBOSE=1" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-fsck - Verifies the connectivity and validity of the objects in the database missing <type> <object>" }, { "role": "assistant", "content": "The <type> object <object>, is referred to but isn’t present in\nthe database." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options system" }, { "role": "assistant", "content": "$(prefix)/etc/gitconfig" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "gitlab get tar of a specific branch via command line\n\nI'm using gitlab. When I go into the interface, on each branch I can download the source code as a zip, tar or whatsoever.\nI am making rpm spec files for which I would need the possibility to download the tar ball using command line. since I added my rsa key i can do git clone without problems:\ngit clone http://gitlab/group/project.git\nCloning into 'project'...\nremote: Counting objects: 1885, done.\nremote: Compressing objects: 100% (826/826), done.\nremote: Total 1885 (delta 1194), reused 1496 (delta 954)\nReceiving objects: 100% (1885/1885), 1.30 MiB | 0 bytes/s, done.\nResolving deltas: 100% (1194/1194), done.\nChecking connectivity... done\n\nHowever doing \nwget http://gitlab/group/project/repository/archive.zip\n\ngets me these errors:\nResolving gitlab (gitlab)... 10.1.253.75\nConnecting to gitlab (gitlab)|10.1.253.75|:80... connected.\nHTTP request sent, awaiting response... 401 Unauthorized\nAuthorization failed." }, { "role": "assistant", "content": "Since GitLab 6.2 and issue 5253, it should be:\nGET /projects/:id/repository/archive\n\nBut that seems for internal use only, since you cannot know the id of a project as a user (only its name).\nDon't forget, as shown in ability.rb, that downloading an archive is linked to a permission. Make sure you have that \"download_code\" permission set for your project.\nHere, it must be a permission issue, because, for instance:\nwget http://demo.gitlab.com/gitlab/gitlab-recipes/repository/archive.zip\n\nThat works just fine, and get the content of that project without any issue.\n\nHowever, as the OP Chris Maes comments and mentions in issue 6645, as as illustrated by app/models/ability.rb:\n if project && project.public?\n\n... that \"dowload_code\" feature is only for public projects." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to use Visual Studio Code as the default editor for Git MergeTool including for 3-way merge\nToday I was trying to use the git mergetool on the Windows command prompt and realized that it was defaulting to use Vim, which is cool, but I'd prefer VS Code.\nHow can I have Visual Studio Code function as my GUI for handling merge conflicts (or even as a diffing tool) for Git?\nIs it possible to setup VS Code to get visuals for a three-way merge?" }, { "role": "assistant", "content": "Update: As of Visual Studio Code 1.70 Three-way merge with improvements were added. Visuals and further explanations are available if that's of interest to you 😉.\nAs of Visual Studio Code 1.13 Better Merge was integrated into\nthe core of Visual Studio Code.\nThe way to wire them together is to modify your .gitconfig and you have two options.\n\nTo do this with command line entries, enter each of these: (Note: if on Windows Command Prompt replace ' with \". Thanks to Iztok Delfin and e4rache for helping clarify this.)\n\ngit config --global merge.tool vscode\ngit config --global mergetool.vscode.cmd 'code --wait --merge $REMOTE $LOCAL $BASE $MERGED'\ngit config --global diff.tool vscode\ngit config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'\n\n\nTo do this by pasting some line in the .gitconfig with Visual Studio Code.\n\nRun git config --global core.editor 'code --wait' from the command line.\n\nFrom here you can enter the command git config --global -e. You will want to paste in the code in the \"Extra Block\" below.\n [user]\n name = EricDJohnson\n email = [email protected]\n [gui]\n recentrepo = E:/src/gitlab/App-Custom/Some-App\n # Comment: You just added this via 'git config --global core.editor \"code --wait\"'\n [core]\n editor = code --wait\n # Comment: Start of \"Extra Block\"\n # Comment: This is to unlock Visual Studio Code as your Git diff and Git merge tool\n [merge]\n tool = vscode\n [mergetool \"vscode\"]\n # Comment: Original way before three-way merge shown commented out\n # cmd = code --wait $MERGED\n # Comment: For \"Three-way merge\"\n cmd = code --wait --merge $REMOTE $LOCAL $BASE $MERGED\n [diff]\n tool = vscode\n [difftool \"vscode\"]\n cmd = code --wait --diff $LOCAL $REMOTE\n # Comment: End of \"Extra Block\"\n\n\n\n\n\nNow from within your Git directory with a conflict run git mergetool and, tada, you have Visual Studio Code helping you handle the merge conflict! (Just make sure to save your file before closing Visual Studio Code.)\n\nFor further reading on launching code from the command line, look in this documentation.\nFor more information in git mergetool check out this documentation." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git: a quick command to go to root of the working tree\nI wanted a simple git command to go up to the \"root\" of the repository.\nI started with a script, but figured that I cannot change active directory of the shell, I had to do a function. Unfortunately, I cannot call it directly with the non-dash form \"git root\", for instance.\nfunction git-root() {\n if [ -d .git ]; then\n return 0\n fi\n\n A=..\n while ! [ -d $A/.git ]; do \n A=\"$A/..\"\n done\n cd $A\n}\n\nDo you have a better solution? (the function has been written quickly, suggestions are welcome)" }, { "role": "assistant", "content": "Simpler still, steal from Is there a way to get the git root directory in one command? , and make an alias (as suggested by Peter) from\ncd \"$(git rev-parse --show-toplevel)\"\n\nThis works whether you're in the root directory or not." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Is Github.com source code open source? [closed]\n\nClosed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.\n \n \n\n\n\n\n\n\n\n\n\n\n\n This question does not appear to be about programming within the scope defined in the help center.\n\n\nClosed 8 years ago.\n\n\n\n\n\n\n\n Improve this question\n \n\n\n\n... or the shoemaker's children go barefoot?\nI would like to fix some styling & have an idea for the feature (and a lot of free time) but I cannot find any github.com page on github.com." }, { "role": "assistant", "content": "GitHub isn't open-source, but you can apply your ideas on an (open-source) GitHub-look-alike:\nGitLab\nA ruby application with its source code here).\nThey accept suggestions and pull requests\n\ngogs.io (less active than gitea)\nUpdate 2015: you also have other GitHub-look-alike in Go:\n\ngitea.com\n\nGitBLit" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Git cannot lock ref 'HEAD': unable to resolve reference HEAD\n\nI'm trying to commit the changes to my repository but I receive the error below:\ngit -c diff.mnemonicprefix=false -c core.quotepath=false commit -q -F C:\\Users\\Contronym\\AppData\\Local\\Temp\\bkdweixb.mnu\nfatal: cannot lock ref 'HEAD': unable to resolve reference HEAD: Invalid argument\n\nCompleted with errors, see above.\n\nI'm using bitbucket and SourceTree.\nWhat's the reason for this commit failing? I was able to commit just fine the last 3 commits over the past week. Then, all of a sudden, I receive this error.\nEDIT\nI ran git gc and these are the results:\n$ git gc\nerror: bad ref for HEAD\nerror: bad ref for HEAD\nerror: inflate: data stream error (unknown compression method)\nfatal: loose object 53b65bd9b4fec7f6a7b0b3313c68199a18804327 (stored in .git/objects/53/b65bd9b4fec7f6a7b0b3313c68199a18804327) is corrupt\nerror: failed to run repack\n\nI checked the directory .git/objects/53/b65bd9b4fec7f6a7b0b3313c68199a18804327 but that doesn't exist. There's two other files there, but b65bd9b4fec7f6a7b0b3313c68199a18804327 doesn't exist." }, { "role": "assistant", "content": "I had the same problem and the only solution that I found was to navigate to the head like so:\n.git/refs/heads/branch_name \n\nAnd I deleted the head file. Then I went to the console and I used the command:\ngit reset\n\nThen all the files were unstaged so add them and commit them afterwards." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git - the stupid content tracker git-update-index" }, { "role": "assistant", "content": "Register file contents in the working tree to the index" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-bisect - Use binary search to find the commit that introduced a bug --first-parent" }, { "role": "assistant", "content": "Follow only the first parent commit upon seeing a merge commit. In detecting regressions introduced through the merging of a branch, the merge\ncommit will be identified as introduction of the bug and its ancestors will be\nignored. This option is particularly useful in avoiding false positives when a merged\nbranch contained broken or non-buildable commits, but the merge itself was OK." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-config - Get and set repository or global options core.alternateRefsPrefixes" }, { "role": "assistant", "content": "When listing references from an alternate, list only references that begin\nwith the given prefix. Prefixes match as if they were given as arguments to git-for-each-ref . To list multiple prefixes, separate them with\nwhitespace. If core.alternateRefsCommand is set, setting core.alternateRefsPrefixes has no effect." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git add only modified changes and ignore untracked files\nI ran \"git status\" and listed below are some files that were modified/or under the heading \"changes not staged for commit\".\nIt also listed some untracked files that I want to ignore (I have a \".gitignore\" file in these directories).\nI want to put the modified files in staging so I can commit them. When I ran \"git add .\", it added the modified files AND the files I want to ignore to staging.\nHow do I add only the modified files and ignore the untracked files if presented with the git status below.\nAlso, are my \".gitignore\" files working properly?\n$ git status\n# On branch addLocation\n# Changes not staged for commit:\n# (use \"git add <file>...\" to update what will be committed)\n# (use \"git checkout -- <file>...\" to discard changes in working directory)\n#\n# modified: someProject/path/domain/viewer/LocationDO.java\n# modified: someProject/path/service/ld/LdService.java\n# modified: someProject/path/service/ld/LdServiceImpl.java\n# modified: someProject/path/web/jsf/viewer/LocationFormAction.java\n# modified: someProject/war/WEB-INF/classes/message/viewer/viewer.properties\n# modified: someProject/war/page/viewer/searchForm.xhtml\n#\n# Untracked files:\n# (use \"git add <file>...\" to include in what will be committed)\n#\n# .metadata/\n# someProject/build/\nno changes added to commit (use \"git add\" and/or \"git commit -a\")" }, { "role": "assistant", "content": "Ideally your .gitignore should prevent the untracked (and ignored) files from being shown in status, added using git add etc. So I would ask you to correct your .gitignore\nYou can do git add -u so that it will stage the modified and deleted files.\nYou can also do git commit -a to commit only the modified and deleted files.\nNote that if you have Git of version before 2.0 and used git add ., then you would need to use git add -u . (See \"Difference of “git add -A” and “git add .”\")." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-fast-import - Backend for fast Git data importers option" }, { "role": "assistant", "content": "Specify any of the options listed under OPTIONS that do not\nchange stream semantic to suit the frontend’s needs. This\ncommand is optional and is not needed to perform an import." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to use conditions in .gitlab-ci.yml variables?\n\nI want to know, if it's possible to set custom Gitlab CI variable from if-else condition statement.\nIn my .gitlab-ci.yml file I have the following:\nvariables:\n PROJECT_VERSION: (if [ \"${CI_COMMIT_TAG}\" == \"\" ]; then \"${CI_COMMIT_REF_NAME}-${CI_PIPELINE_ID}\"; else ${CI_COMMIT_TAG}; fi);\n\nTrying to set project version:\n image: php:7.1-cli\n stage: test\n script:\n # this echoes correct string (eg. \"master-2794\")\n - (if [ \"${CI_COMMIT_TAG}\" == \"\" ]; then echo \"${CI_COMMIT_REF_NAME}-${CI_PIPELINE_ID}\"; else echo ${CI_COMMIT_TAG}; fi);\n # this echoes something like \"(if [ \"\" == \"\" ]; then \"master-2794\"; else ; fi);\"\n - echo $PROJECT_VERSION\n\nCan this be done? If so, what have I missed? Thanks" }, { "role": "assistant", "content": "This is expected behavior.\nCI_COMMIT_TAG is only set to a value in a GitLab job. From https://docs.gitlab.com/ee/ci/variables/README.html\n\nCI_COMMIT_TAG - The commit tag name. Present only when building tags.\n\nTherefore in the variables section CI_COMMIT_TAG is not defined, hence equals to \"\".\nSo if you want to use CI_COMMIT_TAG use in job where tags are defined. See https://docs.gitlab.com/ee/ci/yaml/README.html#tags" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-for-each-ref - Output information on each ref worktreepath" }, { "role": "assistant", "content": "The absolute path to the worktree in which the ref is checked\nout, if it is checked out in any linked worktree. Empty string\notherwise." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-fast-import - Backend for fast Git data importers --rewrite-submodules-from=<name>:<file> --rewrite-submodules-to=<name>:<file>" }, { "role": "assistant", "content": "Rewrite the object IDs for the submodule specified by <name> from the values\nused in the from <file> to those used in the to <file>. The from marks should\nhave been created by git fast-export , and the to marks should have been\ncreated by git fast-import when importing that same submodule. <name> may be any arbitrary string not containing a colon character, but the\nsame value must be used with both options when specifying corresponding marks.\nMultiple submodules may be specified with different values for <name>. It is an\nerror not to use these options in corresponding pairs. These options are primarily useful when converting a repository from one hash\nalgorithm to another; without them, fast-import will fail if it encounters a\nsubmodule because it has no way of writing the object ID into the new hash\nalgorithm." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How to overcome \"'aclocal-1.15' is missing on your system\" warning?\n\nIm trying to run a c++ program on github. (available at the following link https://github.com/mortehu/text-classifier)\nI have a mac, and am trying to run it in the terminal. I think I have downloaded autoconf and automake but am not sure. To run the program I am going to the correct folder in terminal then running\n./configure && make \n\nBut I get the error:\n\nWARNING: 'aclocal-1.15' is missing on your system.\n You should only need it if you modified 'acinclude.m4' or\n 'configure.ac' or m4 files included by 'configure.ac'.\n The 'aclocal' program is part of the GNU Automake package:\n http://www.gnu.org/software/automake\n It also requires GNU Autoconf, GNU m4 and Perl in order to run:\n http://www.gnu.org/software/autoconf\nhttp://www.gnu.org/software/m4/\nhttp://www.perl.org/ make: *** [aclocal.m4] Error 127\n\nI have xcode and g++ and all the things required to run c programs, but as is probably obvious, I have no idea what Im doing.\nWhat is the easiest, simplest way to run the program in the above link? I realise it comes with a readme and example usage but I can not get that to work." }, { "role": "assistant", "content": "Before running ./configure try running autoreconf -f -i. The autoreconf program automatically runs autoheader, aclocal, automake, autopoint and libtoolize as required.\nEdit to add: This is usually caused by checking out code from Git instead of extracting it from a .zip or .tar.gz archive. In order to trigger rebuilds when files change, Git does not preserve files' timestamps, so the configure script might appear to be out of date. As others have mentioned, there are ways to get around this if you don't have a sufficiently recent version of autoreconf.\nAnother edit: This error can also be caused by copying the source folder extracted from an archive with scp to another machine. The timestamps can be updated, suggesting that a rebuild is necessary. To avoid this, copy the archive and extract it in place." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Github deploy keys: How do I authorize more than one repository for a single machine?\n\nI have a host, call it rob. I used ssh-keygen on rob to get a public key, which I gave to github in the add a new deploy key screen for repository cheech. Now I want to deploy chong on rob as well. But if I go to the add new deploy key screen for repository chong on github, and paste in the public key I generated on rob it says key already in use. I thought, if the key was in use, I could clone chong on rob but that says permission denied.\nSo clearly this is more complicated than I thought and it involves having multiple keys or something. What should I do to clone chong on rob?" }, { "role": "assistant", "content": "Once a key has been attached to one repo as a deploy key, it cannot be\nused on another repo. If you're running into this error while setting\nup deploy keys, then you'll need to modify your remote and set up your\n~/.ssh/config file to use a non-existent github.com hostname that\nssh will be able to use to pick the correct ssh deploy key for your\nrepository.\n# first we remove the origin\n$ git remote -v\norigin [email protected]:username/foo.git (fetch)\norigin [email protected]:username/foo.git (push)\n$ git remote rm origin\n\n# here we add a new origin using a host nickname called\n# foo.github.com that we will reference with a Host stanza in our\n# ~/.ssh/config to specify which key to use with which fake hostname.\n$ git remote add origin [email protected]:username/foo.git\n$ git remote -v\norigin [email protected]:username/foo.git (fetch)\norigin [email protected]:username/foo.git (push)\n\nGenerate the deploy key for your repository and name it something\nreasonable like:\n$ ssh-keygen -t rsa -f ~/.ssh/id_rsa-foo -C https://github.com/username/foo\nGenerating public/private rsa key pair.\nEnter passphrase (empty for no passphrase): \nEnter same passphrase again: \nYour identification has been saved in /home/username/.ssh/id_rsa-foo.\nYour public key has been saved in /home/username/.ssh/id_rsa-foo.pub.\nThe key fingerprint is:\nc0:ff:ee:34:24:11:5e:6d:7c:4c:b1:a0:de:ad:be:ef https://github.com/username/foo\nThe key's randomart image is:\n+--[ RSA 2048]----+\n| E o..o.oo. |\n| M o o o .+CoW |\n| + o = o. .. |\n| . . + |\n| S |\n| o . |\n| + |\n| . o |\n| ..o. |\n+-----------------+\n\nOnce you've\nadded the deploy key\nyou will then need to add the following stanza to your ~/.ssh/config file:\nHost fake-hostname-foo.github.com\n Hostname github.com\n IdentityFile ~/.ssh/id_rsa-foo\n\nNow you can test it with:\n$ ssh -T [email protected]\nHi username! You've successfully authenticated, but GitHub\ndoes not provide shell access." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-send-email - Send a collection of patches as emails --[no-]to-cover" }, { "role": "assistant", "content": "If this is set, emails found in To: headers in the first patch of\nthe series (typically the cover letter) are added to the to list\nfor each email set. Default is the value of sendemail.toCover configuration value; if that is unspecified, default to --no-to-cover." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How can I reference a commit in an issue comment on GitHub?\n\nI find a lot of answers on how to reference a GitHub issue in a git comment (using the #xxx notation).\nI'd like to reference a commit in my comment, generating a link to the commit details page?" }, { "role": "assistant", "content": "To reference a commit, simply write its SHA-hash, and it'll automatically get turned into a link.\nthe commit 3e5c1e60269ae0329094de131227285d4682b665 solved the issue...\n\nOr use its prefix\nthe commit 3e5c1e6 solved the issue...\n\nSee also:\n\nThe Autolinked references and URLs / Commit SHAs section of\nWriting on GitHub." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-fast-import - Backend for fast Git data importers reset" }, { "role": "assistant", "content": "Reset an existing branch (or a new branch) to a specific\nrevision. This command must be used to change a branch to\na specific revision without making a commit on it." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How is a tag different from a branch in Git? Which should I use, here?\nI am having some difficulty understanding how to use tags versus branches in git.\nI just moved the current version of our code from cvs to git, and now I'm going to be working on a subset of that code for a particular feature. A few other developers will be working on this as well, but not all developers in our group are going to care about this feature. Should I be creating a branch or a tag? In what situations should I be using one versus the other?" }, { "role": "assistant", "content": "From the theoretical point of view:\n\ntags are symbolic names for a given revision. They always point to the same object (usually: to the same revision); they do not change.\nbranches are symbolic names for line of development. New commits are created on top of branch. The branch pointer naturally advances, pointing to newer and newer commits.\n\n\nFrom the technical point of view:\n\ntags reside in refs/tags/ namespace, and can point to tag objects (annotated and optionally GPG signed tags) or directly to commit object (less used lightweight tag for local names), or in very rare cases even to tree object or blob object (e.g. GPG signature).\nbranches reside in refs/heads/ namespace, and can point only to commit objects. The HEAD pointer must refer to a branch (symbolic reference) or directly to a commit (detached HEAD or unnamed branch).\nremote-tracking branches reside in refs/remotes/<remote>/ namespace, and follow ordinary branches in remote repository <remote>.\n\n\nSee also gitglossary manpage:\n\nbranch \n\nA \"branch\" is an active line of development. The most recent commit on a branch is referred to as the tip of that branch. The tip of the branch is referenced by a branch head, which moves forward as additional development is done on the branch. A single git repository can track an arbitrary number of branches, but your working tree is associated with just one of them (the \"current\" or \"checked out\" branch), and HEAD points to that branch.\n\ntag\n\nA ref pointing to a tag or commit object. In contrast to a head, a tag is not changed by a commit. Tags (not tag objects) are stored in $GIT_DIR/refs/tags/. [...]. A tag is most typically used to mark a particular point in the commit ancestry chain.\n\ntag object\n\nAn object containing a ref pointing to another object, which can contain a message just like a commit object. It can also contain a (PGP) signature, in which case it is called a \"signed tag object\"." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "How can I create a Git repository with the default branch name other than \"master\"?\nIn the Pro Git book, it says\n\n“origin” is not special\nJust like the branch name “master” does not have any special meaning in Git, neither does “origin”. While “master” is the default name for a starting branch when you run git init which is the only reason it’s widely used, “origin” is the default name for a remote when you run git clone. If you run git clone -o booyah instead, then you will have booyah/master as your default remote branch.\n\nThat means, we can use our default branch name as main or main-branch or something like that. I didn't see any option in man git-init which will initialize my repo with a different default branch name.\nGitHub shows how to set the default branch name in its settings page. But I am not talking about how to set it on any specific Git hosting site. I am strictly asking in terms of Git only, not in regards to any specific Git hosting site.\nIs there a way to do that?" }, { "role": "assistant", "content": "Newer Git, New Repo\nSince git version 2.28.0 the git init command now takes a --initial-branch (or -b for short) parameter. These two commands create a new Git repo with a branch named \"trunk\", which always made more sense to me than \"master\" (master of what?):\ngit init --initial-branch=trunk\ngit init -b trunk\n\nThis is configurable with the init.defaultBranch setting. If I want all new repos to have \"trunk\" as the default branch:\ngit config --global init.defaultBranch trunk\n\nOlder Git, New Repo\nSome systems still have older Git installations. My Debian 10 server (Buster, the current stable version as of October 2020) comes with Git 2.20, which does not support the -b option. One option is to create the repository and then change the branch name. This technique works for normal (non-bare) repos:\ngit init\ngit checkout -b trunk\n\nThis creates a new repository with trunk as the current branch instead of master. The branch master does not actually exist--the branches don't get created until they have at least one commit. Until the branch gets created, the branch only exists in .git/HEAD, which explains why the master branch will disappear when you switch to trunk.\nBare Repos\nFor bare repos, you cannot run git checkout (that's what it means to be bare). Instead, you can change HEAD to point at a different branch:\ngit init --bare\ngit symbolic-ref HEAD refs/heads/trunk\n\nOld Repos\nIf you've already committed, you can run git branch -m instead:\ngit init\ntouch file.txt\ngit add file.txt\ngit commit -m 'commit 1'\ngit branch -m trunk\n\nThis renames the branch from master to trunk once it's created.\nThis does seem a bit clunky since the mechanism is different depending on whether the repository is empty, but it works. You can also approach it as \"creating a new branch and deleting master\"." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-fetch - Download objects and refs from another repository --[no-]write-commit-graph" }, { "role": "assistant", "content": "Write a commit-graph after fetching. This overrides the config\nsetting fetch.writeCommitGraph ." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "GitLab CI syntax to write FOR loop statement?\n\nBelow is the script mentioned in the gitlab-ci.yml file. This GitLab CI configuration is valid. But, when the CI/CD build is run, the job fails. Is it something to do with the FOR loop syntax? \ndeploy_dv:\n stage: deploy_dv\n variables:\n GIT_STRATEGY: none\nscript:\n - echo \"Deploying Artifacts...\"\n - echo \"Configure JFrog CLI with parameters of your Artifactory instance\"\n - 'c:\\build-tools\\JFROG-CLI\\jfrog rt config --url %ARTIFACTORY_WEBSITE% --user %ARTIFACTORY_USER% --apikey %APIKEY%'\n - 'cd ..\\artifacts'\n - 'SETLOCAL ENABLEDELAYEDEXPANSION'\n - FOR %%i in (*) do (\n 'c:\\build-tools\\curl\\bin\\curl.exe --header \"PRIVATE-TOKEN:%HCA_ACCESS_TOKEN%\" --insecure https://code.example.com/api/repository/tags/%CI_COMMIT_TAG% | c:\\build-tools\\jq\\jq-win64.exe \".release.description\" > temp.txt'\n 'set /p releasenote=<temp.txt'\n 'rem del temp.txt'\n 'set mydate=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%'\n 'c:\\build-tools\\JFROG-CLI\\jfrog rt u \"%%i\" %ARTIFACTORY_ROOT_PATH%/%PROJECT_NAME%/%%i --build-name=%%i --build-number=%BUILDVERSION% --props releasenote=%releasenote%;releaseversion=%BUILDVERSION%;releasedate=%mydate% --flat=false'\n )\n\n - '%CURL% -X POST -F token=%REPOSITORY_TOKEN% -F ref=master -F \"variables[RELEASE]=false\" -F \"variables[PROGRAM]=test\" --insecure https://code.example.com/api/repository/trigger'\n\n only:\n - /^(dv-)(\\d+\\.)(\\d+\\.)(\\d+)$/\n\nI get this below error:\n $ echo \"Deploying Artifacts...\"\n\"Deploying Artifacts...\"\n$ echo \"Configure JFrog CLI with parameters of your Artifactory instance\"\n\"Configure JFrog CLI with parameters of your Artifactory instance\"\n$ c:\\build-tools\\JFROG-CLI\\jfrog rt config --url %ARTIFACTORY_WEBSITE% --user %ARTIFACTORY_USER% --apikey %APIKEY%\nArtifactory server ID [Default-Server]: $ cd ..\\artifacts\n$ SETLOCAL ENABLEDELAYEDEXPANSION\n$ FOR %%i in (*) do ( 'c:\\build-tools\\curl\\bin\\curl.exe --header \"PRIVATE-TOKEN:%HCA_ACCESS_TOKEN%\" --insecure https://code.example.com/api/repository/tags/%CI_COMMIT_TAG% | c:\\build-tools\\jq\\jq-win64.exe \".release.description\" > temp.txt' 'set /p releasenote=<temp.txt' 'rem del temp.txt' 'set mydate=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%' 'c:\\build-tools\\JFROG-CLI\\jfrog rt u \"%%i\" %ARTIFACTORY_ROOT_PATH%/%PROJECT_NAME%/%%i --build-name=%%i --build-number=%BUILDVERSION% --props releasenote=%releasenote%;releaseversion=%BUILDVERSION%;releasedate=%mydate% --flat=false' )\nThe filename, directory name, or volume label syntax is incorrect.\nERROR: Job failed: exit status 255" }, { "role": "assistant", "content": "Since there is still no good answer to this question, I will give it a try. I used this snippet to start multiple Docker builds for every directory in my repository. Notice the |+ and the > characters, which lets you put multi-line commands in YAML and are part of GitLab syntax.\nLinux example:\nbuild:\n stage: loop\n script:\n - |+\n for i in $(seq 1 3)\n do\n echo \"Hello $i\"\n done\n\nWindows example:\nbuild:\n stage: loop\n script:\n - >\n setlocal enabledelayedexpansion\n for %%a in (\"C:\\Test\\*.txt\") do (\n set FileName=%%~a\n echo Filename is: !FileName!\n )\n endlocal" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "What's the simplest way to list conflicted files in Git?\nI just need a plain list of conflicted files.\nIs there anything simpler than:\ngit ls-files -u | cut -f 2 | sort -u\n\nor:\ngit ls-files -u | awk '{print $4}' | sort | uniq\n\nI guess I could set up a handy alias for that, however was wondering how pros do it. I'd use it to write shell loops e.g. to auto-resolve conflict, etc. Maybe replace that loop by plugging into mergetool.cmd?" }, { "role": "assistant", "content": "Use git diff, with name-only to show only the names, and diff-filter=U to only include 'Unmerged' files (optionally, relative to show paths relative to current working directory) .\ngit diff --name-only --diff-filter=U --relative" } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-log - Show commit logs lines" }, { "role": "assistant", "content": "Compute the dirstat numbers by doing the regular line-based diff\nanalysis, and summing the removed/added line counts. (For binary\nfiles, count 64-byte chunks instead, since binary files have no\nnatural concept of lines). This is a more expensive --dirstat behavior than the changes behavior, but it does count rearranged\nlines within a file as much as other changes. The resulting output\nis consistent with what you get from the other --*stat options." } ]
[ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "git-svn - Bidirectional operation between a Subversion repository and Git -q --quiet" }, { "role": "assistant", "content": "Make git svn less verbose. Specify a second time to make it\neven less verbose." } ]