Restructure and move Git content (#18336)
* Rename map topic * Delete map topic * Rename map topic * Add redirect * Remove last two map topics * Move article on adding a remote into a long-form guide * Move article on changing a remote's URL * Move articles on renaming and removing remotes * Move remote URL article * Fix typo * Remove category index file * Move a few articles to the new category * Move a few more files * Move managing remote repos article * Move the rest of the getting started with git map topic * Move the first half of the using git map topic * Move the rest of the articles and 🔥 the directory * Fix failing test * Remove Using Git from product index * Apply suggestions from code review Co-authored-by: Laura Coursen <lecoursen@github.com> * Apply suggestions from code review Co-authored-by: Laura Coursen <lecoursen@github.com>
This commit is contained in:
111
content/github/getting-started-with-github/about-git-rebase.md
Normal file
111
content/github/getting-started-with-github/about-git-rebase.md
Normal file
@@ -0,0 +1,111 @@
|
||||
---
|
||||
title: About Git rebase
|
||||
redirect_from:
|
||||
- /rebase/
|
||||
- articles/interactive-rebase/
|
||||
- /articles/about-git-rebase
|
||||
- /github/using-git/about-git-rebase
|
||||
intro: 'The `git rebase` command allows you to easily change a series of commits, modifying the history of your repository. You can reorder, edit, or squash commits together.'
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
|
||||
|
||||
Typically, you would use `git rebase` to:
|
||||
|
||||
* Edit previous commit messages
|
||||
* Combine multiple commits into one
|
||||
* Delete or revert commits that are no longer necessary
|
||||
|
||||
{% warning %}
|
||||
|
||||
**Warning**: Because changing your commit history can make things difficult for everyone else using the repository, it's considered bad practice to rebase commits when you've already pushed to a repository. To learn how to safely rebase on {% data variables.product.product_location %}, see "[About pull request merges](/articles/about-pull-request-merges)."
|
||||
|
||||
{% endwarning %}
|
||||
|
||||
### Rebasing commits against a branch
|
||||
|
||||
To rebase all the commits between another branch and the current branch state, you can enter the following command in your shell (either the command prompt for Windows, or the terminal for Mac and Linux):
|
||||
|
||||
```shell
|
||||
$ git rebase --interactive <em>other_branch_name</em>
|
||||
```
|
||||
|
||||
### Rebasing commits against a point in time
|
||||
|
||||
To rebase the last few commits in your current branch, you can enter the following command in your shell:
|
||||
|
||||
```shell
|
||||
$ git rebase --interactive HEAD~7
|
||||
```
|
||||
|
||||
### Commands available while rebasing
|
||||
|
||||
There are six commands available while rebasing:
|
||||
|
||||
<dl>
|
||||
<dt><code>pick</code></dt>
|
||||
<dd><code>pick</code> simply means that the commit is included. Rearranging the order of the <code>pick</code> commands changes the order of the commits when the rebase is underway. If you choose not to include a commit, you should delete the entire line. </dd>
|
||||
|
||||
<dt><code>reword</code></dt>
|
||||
<dd>The <code>reword</code> command is similar to <code>pick</code>, but after you use it, the rebase process will pause and give you a chance to alter the commit message. Any changes made by the commit are not affected. </dd>
|
||||
|
||||
<dt><code>edit</code></dt>
|
||||
<dd>If you choose to <code>edit</code> a commit, you'll be given the chance to amend the commit, meaning that you can add or change the commit entirely. You can also make more commits before you continue the rebase. This allows you to split a large commit into smaller ones, or, remove erroneous changes made in a commit. </dd>
|
||||
|
||||
<dt><code>squash</code></dt>
|
||||
<dd>This command lets you combine two or more commits into a single commit. A commit is squashed into the commit above it. Git gives you the chance to write a new commit message describing both changes.</dd>
|
||||
|
||||
<dt><code>fixup</code></dt>
|
||||
<dd>This is similar to <code>squash</code>, but the commit to be merged has its message discarded. The commit is simply merged into the commit above it, and the earlier commit's message is used to describe both changes.</dd>
|
||||
|
||||
<dt><code>exec</code></dt>
|
||||
<dd>This lets you run arbitrary shell commands against a commit.</dd>
|
||||
</dl>
|
||||
|
||||
### An example of using `git rebase`
|
||||
|
||||
No matter which command you use, Git will launch [your default text editor](/github/getting-started-with-github/associating-text-editors-with-git) and open a file that details the commits in the range you've chosen. That file looks something like this:
|
||||
|
||||
```
|
||||
pick 1fc6c95 Patch A
|
||||
pick 6b2481b Patch B
|
||||
pick dd1475d something I want to split
|
||||
pick c619268 A fix for Patch B
|
||||
pick fa39187 something to add to patch A
|
||||
pick 4ca2acc i cant' typ goods
|
||||
pick 7b36971 something to move before patch B
|
||||
|
||||
# Rebase 41a72e6..7b36971 onto 41a72e6
|
||||
#
|
||||
# Commands:
|
||||
# p, pick = use commit
|
||||
# r, reword = use commit, but edit the commit message
|
||||
# e, edit = use commit, but stop for amending
|
||||
# s, squash = use commit, but meld into previous commit
|
||||
# f, fixup = like "squash", but discard this commit's log message
|
||||
# x, exec = run command (the rest of the line) using shell
|
||||
#
|
||||
# If you remove a line here THAT COMMIT WILL BE LOST.
|
||||
# However, if you remove everything, the rebase will be aborted.
|
||||
#
|
||||
```
|
||||
|
||||
Breaking this information, from top to bottom, we see that:
|
||||
|
||||
- Seven commits are listed, which indicates that there were seven changes between our starting point and our current branch state.
|
||||
- The commits you chose to rebase are sorted in the order of the oldest changes (at the top) to the newest changes (at the bottom).
|
||||
- Each line lists a command (by default, `pick`), the commit SHA, and the commit message. The entire `git rebase` procedure centers around your manipulation of these three columns. The changes you make are *rebased* onto your repository.
|
||||
- After the commits, Git tells you the range of commits we're working with (`41a72e6..7b36971`).
|
||||
- Finally, Git gives some help by telling you the commands that are available to you when rebasing commits.
|
||||
|
||||
### Further reading
|
||||
|
||||
- "[Using Git rebase](/articles/using-git-rebase)"
|
||||
- [The "Git Branching" chapter from the _Pro Git_ book](https://git-scm.com/book/en/Git-Branching-Rebasing)
|
||||
- [The "Interactive Rebasing" chapter from the _Pro Git_ book](https://git-scm.com/book/en/Git-Tools-Rewriting-History#_changing_multiple)
|
||||
- "[Squashing commits with rebase](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html)"
|
||||
- "[Syncing your branch](/desktop/contributing-to-projects/syncing-your-branch)" in the {% data variables.product.prodname_desktop %} documentation
|
||||
@@ -0,0 +1,110 @@
|
||||
---
|
||||
title: About Git subtree merges
|
||||
redirect_from:
|
||||
- /articles/working-with-subtree-merge/
|
||||
- /subtree-merge/
|
||||
- /articles/about-git-subtree-merges
|
||||
- /github/using-git/about-git-subtree-merges
|
||||
intro: 'If you need to manage multiple projects within a single repository, you can use a *subtree merge* to handle all the references.'
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
Typically, a subtree merge is used to contain a repository within a repository. The "subrepository" is stored in a folder of the main repository.
|
||||
|
||||
The best way to explain subtree merges is to show by example. We will:
|
||||
|
||||
- Make an empty repository called `test` that represents our project
|
||||
- Merge another repository into it as a subtree called `Spoon-Knife`.
|
||||
- The `test` project will use that subproject as if it were part of the same repository.
|
||||
- Fetch updates from `Spoon-Knife` into our `test` project.
|
||||
|
||||
### Setting up the empty repository for a subtree merge
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
2. Create a new directory and navigate to it.
|
||||
```shell
|
||||
$ mkdir test
|
||||
$ cd test
|
||||
```
|
||||
3. Initialize a new Git repository.
|
||||
```shell
|
||||
$ git init
|
||||
> Initialized empty Git repository in /Users/octocat/tmp/test/.git/
|
||||
```
|
||||
4. Create and commit a new file.
|
||||
```shell
|
||||
$ touch .gitignore
|
||||
$ git add .gitignore
|
||||
$ git commit -m "initial commit"
|
||||
> [main (root-commit) 3146c2a] initial commit
|
||||
> 0 files changed, 0 insertions(+), 0 deletions(-)
|
||||
> create mode 100644 .gitignore
|
||||
```
|
||||
|
||||
### Adding a new repository as a subtree
|
||||
|
||||
1. Add a new remote URL pointing to the separate project that we're interested in.
|
||||
```shell
|
||||
$ git remote add -f spoon-knife git@github.com:octocat/Spoon-Knife.git
|
||||
> Updating spoon-knife
|
||||
> warning: no common commits
|
||||
> remote: Counting objects: 1732, done.
|
||||
> remote: Compressing objects: 100% (750/750), done.
|
||||
> remote: Total 1732 (delta 1086), reused 1558 (delta 967)
|
||||
> Receiving objects: 100% (1732/1732), 528.19 KiB | 621 KiB/s, done.
|
||||
> Resolving deltas: 100% (1086/1086), done.
|
||||
> From git://github.com/octocat/Spoon-Knife
|
||||
> * [new branch] main -> Spoon-Knife/main
|
||||
```
|
||||
2. Merge the `Spoon-Knife` project into the local Git project. This doesn't change any of your files locally, but it does prepare Git for the next step.
|
||||
|
||||
If you're using Git 2.9 or above:
|
||||
```shell
|
||||
$ git merge -s ours --no-commit --allow-unrelated-histories spoon-knife/main
|
||||
> Automatic merge went well; stopped before committing as requested
|
||||
```
|
||||
|
||||
If you're using Git 2.8 or below:
|
||||
```shell
|
||||
$ git merge -s ours --no-commit spoon-knife/main
|
||||
> Automatic merge went well; stopped before committing as requested
|
||||
```
|
||||
3. Create a new directory called **spoon-knife**, and copy the Git history of the `Spoon-Knife` project into it.
|
||||
```shell
|
||||
$ git read-tree --prefix=spoon-knife/ -u spoon-knife/main
|
||||
```
|
||||
4. Commit the changes to keep them safe.
|
||||
```shell
|
||||
$ git commit -m "Subtree merged in spoon-knife"
|
||||
> [main fe0ca25] Subtree merged in spoon-knife
|
||||
```
|
||||
|
||||
Although we've only added one subproject, any number of subprojects can be incorporated into a Git repository.
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tip**: If you create a fresh clone of the repository in the future, the remotes you've added will not be created for you. You will have to add them again using [the `git remote add` command](/github/getting-started-with-github/managing-remote-repositories).
|
||||
|
||||
{% endtip %}
|
||||
|
||||
### Synchronizing with updates and changes
|
||||
|
||||
When a subproject is added, it is not automatically kept in sync with the upstream changes. You will need to update the subproject with the following command:
|
||||
|
||||
```shell
|
||||
$ git pull -s subtree <em>remotename</em> <em>branchname</em>
|
||||
```
|
||||
|
||||
For the example above, this would be:
|
||||
|
||||
```shell
|
||||
$ git pull -s subtree spoon-knife main
|
||||
```
|
||||
|
||||
### Further reading
|
||||
|
||||
- [The "Advanced Merging" chapter from the _Pro Git_ book](https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging)
|
||||
- "[How to use the subtree merge strategy](https://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html)"
|
||||
@@ -0,0 +1,96 @@
|
||||
---
|
||||
title: About remote repositories
|
||||
redirect_from:
|
||||
- /articles/working-when-github-goes-down/
|
||||
- /articles/sharing-repositories-without-github/
|
||||
- /articles/about-remote-repositories
|
||||
- /articles/which-url-should-i-use/
|
||||
- /articles/which-remote-url-should-i-use
|
||||
- /github/using-git/which-remote-url-should-i-use
|
||||
- /github/using-git/about-remote-repositories
|
||||
intro: 'GitHub''s collaborative approach to development depends on publishing commits from your local repository to {% data variables.product.product_name %} for other people to view, fetch, and update.'
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
### About remote repositories
|
||||
|
||||
A remote URL is Git's fancy way of saying "the place where your code is stored." That URL could be your repository on GitHub, or another user's fork, or even on a completely different server.
|
||||
|
||||
You can only push to two types of URL addresses:
|
||||
|
||||
* An HTTPS URL like `https://{% data variables.command_line.backticks %}/user/repo.git`
|
||||
* An SSH URL, like `git@{% data variables.command_line.backticks %}:user/repo.git`
|
||||
|
||||
Git associates a remote URL with a name, and your default remote is usually called `origin`.
|
||||
|
||||
### Creating remote repositories
|
||||
|
||||
You can use the `git remote add` command to match a remote URL with a name.
|
||||
For example, you'd type the following in the command line:
|
||||
|
||||
```shell
|
||||
git remote add origin <em> <REMOTE_URL> </em>
|
||||
```
|
||||
|
||||
This associates the name `origin` with the `REMOTE_URL`.
|
||||
|
||||
You can use the command `git remote set-url` to [change a remote's URL](/github/getting-started-with-github/managing-remote-repositories).
|
||||
|
||||
### Choosing a URL for your remote repository
|
||||
|
||||
There are several ways to clone repositories available on {% data variables.product.product_location %}.
|
||||
|
||||
When you view a repository while signed in to your account, the URLs you can use to clone the project onto your computer are available below the repository details.
|
||||
|
||||
For information on setting or changing your remote URL, see "[Managing remote repositories](/github/getting-started-with-github/managing-remote-repositories)."
|
||||
|
||||
### Cloning with HTTPS URLs
|
||||
|
||||
The `https://` clone URLs are available on all repositories, regardless of visibility. `https://` clone URLs work even if you are behind a firewall or proxy.
|
||||
|
||||
When you `git clone`, `git fetch`, `git pull`, or `git push` to a remote repository using HTTPS URLs on the command line, Git will ask for your {% data variables.product.product_name %} username and password. {% data reusables.user_settings.password-authentication-deprecation %}
|
||||
|
||||
{% data reusables.command_line.provide-an-access-token %}
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tips**:
|
||||
- You can use a credential helper so Git will remember your {% data variables.product.prodname_dotcom %} credentials every time it talks to {% data variables.product.prodname_dotcom %}. For more information, see "[Caching your {% data variables.product.prodname_dotcom %} credentials in Git](/github/getting-started-with-github/caching-your-github-credentials-in-git)."
|
||||
- To clone a repository without authenticating to {% data variables.product.product_name %} on the command line, you can use {% data variables.product.prodname_desktop %} to clone instead. For more information, see "[Cloning a repository from {% data variables.product.prodname_dotcom %} to {% data variables.product.prodname_dotcom %} Desktop](/desktop/contributing-to-projects/cloning-a-repository-from-github-to-github-desktop)."
|
||||
|
||||
{% endtip %}
|
||||
|
||||
{% if currentVersion == "free-pro-team@latest" %}If you'd rather use SSH but cannot connect over port 22, you might be able to use SSH over the HTTPS port. For more information, see "[Using SSH over the HTTPS port](/github/authenticating-to-github/using-ssh-over-the-https-port)."{% endif %}
|
||||
|
||||
### Cloning with SSH URLs
|
||||
|
||||
SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and add the **public** key to your {% data variables.product.product_name %} account. For more information, see "[Connecting to {% data variables.product.prodname_dotcom %} with SSH](/github/authenticating-to-github/connecting-to-github-with-ssh)."
|
||||
|
||||
When you `git clone`, `git fetch`, `git pull`, or `git push` to a remote repository using SSH URLs, you'll be prompted for a password and must provide your SSH key passphrase. For more information, see "[Working with SSH key passphrases](/github/authenticating-to-github/working-with-ssh-key-passphrases)."
|
||||
|
||||
{% if currentVersion == "free-pro-team@latest" %}If you are accessing an organization that uses SAML single sign-on (SSO), you must authorize your SSH key to access the organization before you authenticate. For more information, see "[About authentication with SAML single sign-on](/github/authenticating-to-github/about-authentication-with-saml-single-sign-on)" and "[Authorizing an SSH key for use with SAML single sign-on](/github/authenticating-to-github/authorizing-an-ssh-key-for-use-with-saml-single-sign-on)."{% endif %}
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tip**: You can use an SSH URL to clone a repository to your computer, or as a secure way of deploying your code to production servers. You can also use SSH agent forwarding with your deploy script to avoid managing keys on the server. For more information, see "[Using SSH Agent Forwarding](/developers/overview/using-ssh-agent-forwarding)."
|
||||
|
||||
{% endtip %}
|
||||
|
||||
{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.19" or currentVersion == "github-ae@latest" %}
|
||||
|
||||
### Cloning with {% data variables.product.prodname_cli %}
|
||||
|
||||
You can also install {% data variables.product.prodname_cli %} to use {% data variables.product.product_name %} workflows in your terminal. For more information, the [{% data variables.product.prodname_cli %}](https://cli.github.com/manual/) documentation.
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if currentVersion != "github-ae@latest" %}
|
||||
### Cloning with Subversion
|
||||
|
||||
You can also use a [Subversion](https://subversion.apache.org/) client to access any repository on {% data variables.product.prodname_dotcom %}. Subversion offers a different feature set than Git. For more information, see "[What are the differences between Subversion and Git?](/github/importing-your-projects-to-github/what-are-the-differences-between-subversion-and-git)"
|
||||
|
||||
You can also access repositories on {% data variables.product.prodname_dotcom %} from Subversion clients. For more information, see "[Support for Subversion clients](/github/importing-your-projects-to-github/support-for-subversion-clients)."
|
||||
{% endif %}
|
||||
@@ -0,0 +1,123 @@
|
||||
---
|
||||
title: Associating text editors with Git
|
||||
intro: Use a text editor to open and edit your files with Git.
|
||||
redirect_from:
|
||||
- /textmate/
|
||||
- /articles/using-textmate-as-your-default-editor/
|
||||
- /articles/using-sublime-text-2-as-your-default-editor/
|
||||
- /articles/associating-text-editors-with-git
|
||||
- /github/using-git/associating-text-editors-with-git
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
{% mac %}
|
||||
|
||||
### Using Atom as your editor
|
||||
|
||||
1. Install [Atom](https://atom.io/). For more information, see "[Installing Atom](https://flight-manual.atom.io/getting-started/sections/installing-atom/)" in the Atom documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "atom --wait"
|
||||
```
|
||||
|
||||
### Using Visual Studio Code as your editor
|
||||
|
||||
1. Install [Visual Studio Code](https://code.visualstudio.com/) (VS Code). For more information, see "[Setting up Visual Studio Code](https://code.visualstudio.com/Docs/setup/setup-overview)" in the VS Code documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "code --wait"
|
||||
```
|
||||
|
||||
### Using Sublime Text as your editor
|
||||
|
||||
1. Install [Sublime Text](https://www.sublimetext.com/). For more information, see "[Installation](https://docs.sublimetext.io/guide/getting-started/installation.html)" in the Sublime Text documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "subl -n -w"
|
||||
```
|
||||
|
||||
### Using TextMate as your editor
|
||||
|
||||
1. Install [TextMate](https://macromates.com/).
|
||||
2. Install TextMate's `mate` shell utility. For more information, see "[mate and rmate](https://macromates.com/blog/2011/mate-and-rmate/)" in the TextMate documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
4. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "mate -w"
|
||||
```
|
||||
{% endmac %}
|
||||
|
||||
{% windows %}
|
||||
|
||||
### Using Atom as your editor
|
||||
|
||||
1. Install [Atom](https://atom.io/). For more information, see "[Installing Atom](https://flight-manual.atom.io/getting-started/sections/installing-atom/)" in the Atom documentation.
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "atom --wait"
|
||||
```
|
||||
|
||||
### Using Visual Studio Code as your editor
|
||||
|
||||
1. Install [Visual Studio Code](https://code.visualstudio.com/) (VS Code). For more information, see "[Setting up Visual Studio Code](https://code.visualstudio.com/Docs/setup/setup-overview)" in the VS Code documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "code --wait"
|
||||
```
|
||||
|
||||
### Using Sublime Text as your editor
|
||||
|
||||
1. Install [Sublime Text](https://www.sublimetext.com/). For more information, see "[Installation](https://docs.sublimetext.io/guide/getting-started/installation.html)" in the Sublime Text documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "'C:/Program Files (x86)/sublime text 3/subl.exe' -w"
|
||||
```
|
||||
|
||||
### Using Notepad++ as your editor
|
||||
|
||||
1. Install Notepad++ from https://notepad-plus-plus.org/. For more information, see "[Getting started](https://npp-user-manual.org/docs/getting-started/)" in the Notepad++ documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
|
||||
```
|
||||
{% endwindows %}
|
||||
|
||||
{% linux %}
|
||||
|
||||
### Using Atom as your editor
|
||||
|
||||
1. Install [Atom](https://atom.io/). For more information, see "[Installing Atom](https://flight-manual.atom.io/getting-started/sections/installing-atom/)" in the Atom documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "atom --wait"
|
||||
```
|
||||
|
||||
### Using Visual Studio Code as your editor
|
||||
|
||||
1. Install [Visual Studio Code](https://code.visualstudio.com/) (VS Code). For more information, see "[Setting up Visual Studio Code](https://code.visualstudio.com/Docs/setup/setup-overview)" in the VS Code documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "code --wait"
|
||||
```
|
||||
|
||||
### Using Sublime Text as your editor
|
||||
|
||||
1. Install [Sublime Text](https://www.sublimetext.com/). For more information, see "[Installation](https://docs.sublimetext.io/guide/getting-started/installation.html)" in the Sublime Text documentation.
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
3. Type this command:
|
||||
```shell
|
||||
$ git config --global core.editor "subl -n -w"
|
||||
```
|
||||
|
||||
{% endlinux %}
|
||||
@@ -0,0 +1,103 @@
|
||||
---
|
||||
title: Caching your GitHub credentials in Git
|
||||
redirect_from:
|
||||
- /firewalls-and-proxies/
|
||||
- /articles/caching-your-github-password-in-git
|
||||
- /github/using-git/caching-your-github-password-in-git
|
||||
- /github/using-git/caching-your-github-credentials-in-git
|
||||
intro: 'If you''re [cloning {% data variables.product.product_name %} repositories using HTTPS](/github/getting-started-with-github/about-remote-repositories), you can use a credential helper to tell Git to remember your credentials.'
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
If you clone {% data variables.product.product_name %} repositories using SSH, then you authenticate using an SSH key instead of using other credentials. For information about setting up an SSH connection, see "[Generating an SSH Key](/articles/generating-an-ssh-key)."
|
||||
|
||||
{% mac %}
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tips:**
|
||||
|
||||
- You need Git **1.7.10** or newer to use the osxkeychain credential helper.
|
||||
- If you installed Git using [Homebrew](http://brew.sh/), the `osxkeychain helper` will already be installed.
|
||||
- If you're running Mac OS X 10.7 and above and you installed Git through Apple's Xcode Command Line Tools, then `osxkeychain helper` is automatically included in your Git installation.
|
||||
|
||||
{% endtip %}
|
||||
|
||||
Install Git and the `osxkeychain helper` and tell Git to use it.
|
||||
|
||||
1. Find out if Git and the `osxkeychain helper` are already installed:
|
||||
```shell
|
||||
$ git credential-osxkeychain
|
||||
# Test for the cred helper
|
||||
> Usage: git credential-osxkeychain <get|store|erase>
|
||||
```
|
||||
2. If the `osxkeychain helper` isn't installed and you're running OS X version 10.9 or above, your computer will prompt you to download it as a part of the Xcode Command Line Tools:
|
||||
```shell
|
||||
$ git credential-osxkeychain
|
||||
> xcode-select: note: no developer tools were found at '/Applications/Xcode.app',
|
||||
> requesting install. Choose an option in the dialog to download the command line developer tools.
|
||||
```
|
||||
|
||||
Alternatively, you can install Git and the `osxkeychain helper` by using [Homebrew](http://brew.sh/):
|
||||
```shell
|
||||
$ brew install git
|
||||
```
|
||||
|
||||
4. Tell Git to use `osxkeychain helper` using the global `credential.helper` config:
|
||||
```shell
|
||||
$ git config --global credential.helper osxkeychain
|
||||
# Set git to use the osxkeychain credential helper
|
||||
```
|
||||
|
||||
The next time you clone an HTTPS URL that requires authentication, Git will prompt you for your username and password. {% data reusables.user_settings.password-authentication-deprecation %}
|
||||
|
||||
Once you've authenticated successfully, your credentials are stored in the macOS keychain and will be used every time you clone an HTTPS URL. You won't be required to type your credentials in to Git again unless you change your credentials.
|
||||
|
||||
{% endmac %}
|
||||
|
||||
{% windows %}
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tip:** You need Git **1.7.10** or newer to use the credential helper.
|
||||
|
||||
{% endtip %}
|
||||
|
||||
You can also install a native Git shell, such as [Git for Windows](https://git-for-windows.github.io/). With Git for Windows, running the following in the command line will store your credentials:
|
||||
|
||||
```shell
|
||||
$ git config --global credential.helper wincred
|
||||
```
|
||||
|
||||
{% endwindows %}
|
||||
|
||||
{% linux %}
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tip:** You need Git **1.7.10** or newer to use the credential helper.
|
||||
|
||||
{% endtip %}
|
||||
|
||||
Turn on the credential helper so that Git will save your password in memory for some time. By default, Git will cache your password for 15 minutes.
|
||||
|
||||
1. In Terminal, enter the following:
|
||||
```shell
|
||||
$ git config --global credential.helper cache
|
||||
# Set git to use the credential memory cache
|
||||
```
|
||||
2. To change the default password cache timeout, enter the following:
|
||||
```shell
|
||||
$ git config --global credential.helper 'cache --timeout=3600'
|
||||
# Set the cache to timeout after 1 hour (setting is in seconds)
|
||||
```
|
||||
|
||||
{% endlinux %}
|
||||
|
||||
### Further reading
|
||||
|
||||
- "[Updating credentials from the OSX Keychain](/articles/updating-credentials-from-the-osx-keychain/)"
|
||||
- "[Creating a personal access token](/github/authenticating-to-github/creating-a-personal-access-token)"
|
||||
@@ -0,0 +1,131 @@
|
||||
---
|
||||
title: Configuring Git to handle line endings
|
||||
intro: 'To avoid problems in your diffs, you can configure Git to properly handle line endings.'
|
||||
redirect_from:
|
||||
- /dealing-with-lineendings/
|
||||
- /line-endings/
|
||||
- /articles/dealing-with-line-endings/
|
||||
- /articles/configuring-git-to-handle-line-endings
|
||||
- /github/using-git/configuring-git-to-handle-line-endings
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
Every time you press <kbd>return</kbd> on your keyboard you insert an invisible character called a line ending. Different operating systems handle line endings differently.
|
||||
|
||||
When you're collaborating on projects with Git and {% data variables.product.product_name %}, Git might produce unexpected results if, for example, you're working on a Windows machine, and your collaborator has made a change in OS X.
|
||||
|
||||
You can configure Git to handle line endings automatically so you can collaborate effectively with people who use different operating systems.
|
||||
|
||||
### Global settings for line endings
|
||||
|
||||
The `git config core.autocrlf` command is used to change how Git handles line endings. It takes a single argument.
|
||||
|
||||
{% mac %}
|
||||
|
||||
On OS X, you simply pass `input` to the configuration. For example:
|
||||
|
||||
```shell
|
||||
$ git config --global core.autocrlf input
|
||||
# Configure Git to ensure line endings in files you checkout are correct for OS X
|
||||
```
|
||||
|
||||
{% endmac %}
|
||||
|
||||
{% windows %}
|
||||
|
||||
On Windows, you simply pass `true` to the configuration. For example:
|
||||
|
||||
```shell
|
||||
$ git config --global core.autocrlf true
|
||||
# Configure Git to ensure line endings in files you checkout are correct for Windows.
|
||||
# For compatibility, line endings are converted to Unix style when you commit files.
|
||||
```
|
||||
|
||||
{% endwindows %}
|
||||
|
||||
{% linux %}
|
||||
|
||||
On Linux, you simply pass `input` to the configuration. For example:
|
||||
|
||||
```shell
|
||||
$ git config --global core.autocrlf input
|
||||
# Configure Git to ensure line endings in files you checkout are correct for Linux
|
||||
```
|
||||
|
||||
{% endlinux %}
|
||||
|
||||
### Per-repository settings
|
||||
|
||||
Optionally, you can configure a *.gitattributes* file to manage how Git reads line endings in a specific repository. When you commit this file to a repository, it overrides the `core.autocrlf` setting for all repository contributors. This ensures consistent behavior for all users, regardless of their Git settings and environment.
|
||||
|
||||
The *.gitattributes* file must be created in the root of the repository and committed like any other file.
|
||||
|
||||
A *.gitattributes* file looks like a table with two columns:
|
||||
|
||||
* On the left is the file name for Git to match.
|
||||
* On the right is the line ending configuration that Git should use for those files.
|
||||
|
||||
#### Example
|
||||
|
||||
Here's an example *.gitattributes* file. You can use it as a template for your repositories:
|
||||
|
||||
```
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Explicitly declare text files you want to always be normalized and converted
|
||||
# to native line endings on checkout.
|
||||
*.c text
|
||||
*.h text
|
||||
|
||||
# Declare files that will always have CRLF line endings on checkout.
|
||||
*.sln text eol=crlf
|
||||
|
||||
# Denote all files that are truly binary and should not be modified.
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
```
|
||||
|
||||
You'll notice that files are matched—`*.c`, `*.sln`, `*.png`—, separated by a space, then given a setting—`text`, `text eol=crlf`, `binary`. We'll go over some possible settings below.
|
||||
|
||||
- `text=auto` Git will handle the files in whatever way it thinks is best. This is a good default option.
|
||||
|
||||
- `text eol=crlf` Git will always convert line endings to `CRLF` on checkout. You should use this for files that must keep `CRLF` endings, even on OSX or Linux.
|
||||
|
||||
- `text eol=lf` Git will always convert line endings to `LF` on checkout. You should use this for files that must keep LF endings, even on Windows.
|
||||
|
||||
- `binary` Git will understand that the files specified are not text, and it should not try to change them. The `binary` setting is also an alias for `-text -diff`.
|
||||
|
||||
### Refreshing a repository after changing line endings
|
||||
|
||||
When you set the `core.autocrlf` option or commit a *.gitattributes* file, you may find that Git reports changes to files that you have not modified. Git has changed line endings to match your new configuration.
|
||||
|
||||
To ensure that all the line endings in your repository match your new configuration, backup your files with Git, delete all files in your repository (except the `.git` directory), then restore the files all at once.
|
||||
|
||||
1. Save your current files in Git, so that none of your work is lost.
|
||||
```shell
|
||||
$ git add . -u
|
||||
$ git commit -m "Saving files before refreshing line endings"
|
||||
```
|
||||
2. Add all your changed files back and normalize the line endings.
|
||||
```shell
|
||||
$ git add --renormalize .
|
||||
```
|
||||
3. Show the rewritten, normalized files.
|
||||
```shell
|
||||
$ git status
|
||||
```
|
||||
4. Commit the changes to your repository.
|
||||
```shell
|
||||
$ git commit -m "Normalize all the line endings"
|
||||
```
|
||||
|
||||
### Further reading
|
||||
|
||||
- [Customizing Git - Git Attributes](https://git-scm.com/book/en/Customizing-Git-Git-Attributes) in the Pro Git book
|
||||
- [git-config](https://git-scm.com/docs/git-config) in the man pages for Git
|
||||
- [Getting Started - First-Time Git Setup](https://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup) in the Pro Git book
|
||||
- [Mind the End of Your Line](http://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line/) by [Tim Clem](https://github.com/tclem)
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
title: Dealing with non-fast-forward errors
|
||||
intro: 'Sometimes, Git can''t make your change to a remote repository without losing commits. When this happens, your push is refused.'
|
||||
redirect_from:
|
||||
- /articles/dealing-with-non-fast-forward-errors
|
||||
- /github/using-git/dealing-with-non-fast-forward-errors
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
If another person has pushed to the same branch as you, Git won't be able to push your changes:
|
||||
|
||||
```shell
|
||||
$ git push origin main
|
||||
> To https://{% data variables.command_line.codeblock %}/<em>USERNAME</em>/<em>REPOSITORY</em>.git
|
||||
> ! [rejected] main -> main (non-fast-forward)
|
||||
> error: failed to push some refs to 'https://{% data variables.command_line.codeblock %}/<em>USERNAME</em>/<em>REPOSITORY</em>.git'
|
||||
> To prevent you from losing history, non-fast-forward updates were rejected
|
||||
> Merge the remote changes (e.g. 'git pull') before pushing again. See the
|
||||
> 'Note about fast-forwards' section of 'git push --help' for details.
|
||||
```
|
||||
|
||||
You can fix this by [fetching and merging](/github/getting-started-with-github/getting-changes-from-a-remote-repository) the changes made on the remote branch with the changes that you have made locally:
|
||||
|
||||
```shell
|
||||
$ git fetch origin
|
||||
# Fetches updates made to an online repository
|
||||
$ git merge origin <em>YOUR_BRANCH_NAME</em>
|
||||
# Merges updates made online with your local work
|
||||
```
|
||||
|
||||
Or, you can simply use `git pull` to perform both commands at once:
|
||||
|
||||
```shell
|
||||
$ git pull origin <em>YOUR_BRANCH_NAME</em>
|
||||
# Grabs online updates and merges them with your local work
|
||||
```
|
||||
@@ -0,0 +1,81 @@
|
||||
---
|
||||
title: Getting changes from a remote repository
|
||||
intro: You can use common Git commands to access remote repositories.
|
||||
redirect_from:
|
||||
- /articles/fetching-a-remote/
|
||||
- /articles/getting-changes-from-a-remote-repository
|
||||
- /github/using-git/getting-changes-from-a-remote-repository
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
These commands are very useful when interacting with [a remote repository](/github/getting-started-with-github/about-remote-repositories). `clone` and `fetch` download remote code from a repository's remote URL to your local computer, `merge` is used to merge different people's work together with yours, and `pull` is a combination of `fetch` and `merge`.
|
||||
|
||||
### Cloning a repository
|
||||
|
||||
To grab a complete copy of another user's repository, use `git clone` like this:
|
||||
|
||||
```shell
|
||||
$ git clone https://{% data variables.command_line.codeblock %}/<em>USERNAME</em>/<em>REPOSITORY</em>.git
|
||||
# Clones a repository to your computer
|
||||
```
|
||||
|
||||
You can choose from [several different URLs](/github/getting-started-with-github/about-remote-repositories) when cloning a repository. While logged in to {% data variables.product.prodname_dotcom %}, these URLs are available below the repository details:
|
||||
|
||||

|
||||
|
||||
When you run `git clone`, the following actions occur:
|
||||
- A new folder called `repo` is made
|
||||
- It is initialized as a Git repository
|
||||
- A remote named `origin` is created, pointing to the URL you cloned from
|
||||
- All of the repository's files and commits are downloaded there
|
||||
- The default branch is checked out
|
||||
|
||||
For every branch `foo` in the remote repository, a corresponding remote-tracking branch
|
||||
`refs/remotes/origin/foo` is created in your local repository. You can usually abbreviate
|
||||
such remote-tracking branch names to `origin/foo`.
|
||||
|
||||
### Fetching changes from a remote repository
|
||||
|
||||
Use `git fetch` to retrieve new work done by other people. Fetching from a repository grabs all the new remote-tracking branches and tags *without* merging those changes into your own branches.
|
||||
|
||||
If you already have a local repository with a remote URL set up for the desired project, you can grab all the new information by using `git fetch *remotename*` in the terminal:
|
||||
|
||||
```shell
|
||||
$ git fetch <em>remotename</em>
|
||||
# Fetches updates made to a remote repository
|
||||
```
|
||||
|
||||
Otherwise, you can always add a new remote and then fetch. For more information, see "[Managing remote repositories](/github/getting-started-with-github/managing-remote-repositories)."
|
||||
|
||||
### Merging changes into your local branch
|
||||
|
||||
Merging combines your local changes with changes made by others.
|
||||
|
||||
Typically, you'd merge a remote-tracking branch (i.e., a branch fetched from a remote repository) with your local branch:
|
||||
|
||||
```shell
|
||||
$ git merge <em>remotename</em>/<em>branchname</em>
|
||||
# Merges updates made online with your local work
|
||||
```
|
||||
|
||||
### Pulling changes from a remote repository
|
||||
|
||||
`git pull` is a convenient shortcut for completing both `git fetch` and `git merge `in the same command:
|
||||
|
||||
```shell
|
||||
$ git pull <em>remotename</em> <em>branchname</em>
|
||||
# Grabs online updates and merges them with your local work
|
||||
```
|
||||
|
||||
Because `pull` performs a merge on the retrieved changes, you should ensure that
|
||||
your local work is committed before running the `pull` command. If you run into
|
||||
[a merge conflict](/articles/resolving-a-merge-conflict-using-the-command-line)
|
||||
you cannot resolve, or if you decide to quit the merge, you can use `git merge --abort`
|
||||
to take the branch back to where it was in before you pulled.
|
||||
|
||||
### Further reading
|
||||
|
||||
- ["Working with Remotes" from the _Pro Git_ book](https://git-scm.com/book/en/Git-Basics-Working-with-Remotes)"{% if currentVersion == "free-pro-team@latest" %}
|
||||
- "[Troubleshooting connectivity problems](/articles/troubleshooting-connectivity-problems)"{% endif %}
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
title: Getting started with Git
|
||||
intro: ''
|
||||
mapTopic: true
|
||||
redirect_from:
|
||||
- /articles/getting-started-with-git-and-github
|
||||
- /github/using-git/getting-started-with-git-and-github
|
||||
- /github/using-git/learning-about-git
|
||||
- /articles/learning-about-git
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
13
content/github/getting-started-with-github/git-workflows.md
Normal file
13
content/github/getting-started-with-github/git-workflows.md
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: Git workflows
|
||||
intro: '{% data variables.product.prodname_dotcom %} flow is a lightweight, branch-based workflow that supports teams and projects that deploy regularly.'
|
||||
redirect_from:
|
||||
- /articles/what-is-a-good-git-workflow/
|
||||
- /articles/git-workflows
|
||||
- /github/using-git/git-workflows
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
You can adopt the {% data variables.product.prodname_dotcom %} flow method to standardize how your team functions and collaborates on {% data variables.product.prodname_dotcom %}. For more information, see "[GitHub flow](/github/collaborating-with-issues-and-pull-requests/github-flow)" and "[Understanding the GitHub flow](http://guides.github.com/overviews/flow/)" in the {% data variables.product.prodname_dotcom %} Guides.
|
||||
62
content/github/getting-started-with-github/ignoring-files.md
Normal file
62
content/github/getting-started-with-github/ignoring-files.md
Normal file
@@ -0,0 +1,62 @@
|
||||
---
|
||||
title: Ignoring files
|
||||
redirect_from:
|
||||
- /git-ignore/
|
||||
- /ignore-files/
|
||||
- /articles/ignoring-files
|
||||
- /github/using-git/ignoring-files
|
||||
intro: 'You can configure Git to ignore files you don''t want to check in to {% data variables.product.product_name %}.'
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
### Configuring ignored files for a single repository
|
||||
|
||||
You can create a *.gitignore* file in your repository's root directory to tell Git which files and directories to ignore when you make a commit.
|
||||
To share the ignore rules with other users who clone the repository, commit the *.gitignore* file in to your repository.
|
||||
|
||||
GitHub maintains an official list of recommended *.gitignore* files for many popular operating systems, environments, and languages in the `github/gitignore` public repository. You can also use gitignore.io to create a *.gitignore* file for your operating system, programming language, or IDE. For more information, see "[github/gitignore](https://github.com/github/gitignore)" and the "[gitignore.io](https://www.gitignore.io/)" site.
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
2. Navigate to the location of your Git repository.
|
||||
3. Create a *.gitignore* file for your repository.
|
||||
```shell
|
||||
$ touch .gitignore
|
||||
```
|
||||
|
||||
For an example *.gitignore* file, see "[Some common .gitignore configurations](https://gist.github.com/octocat/9257657)" in the Octocat repository.
|
||||
|
||||
If you want to ignore a file that is already checked in, you must untrack the file before you add a rule to ignore it. From your terminal, untrack the file.
|
||||
|
||||
```shell
|
||||
$ git rm --cached <em>FILENAME</em>
|
||||
```
|
||||
|
||||
### Configuring ignored files for all repositories on your computer
|
||||
|
||||
You can also create a global *.gitignore* file to define a list of rules for ignoring files in every Git repository on your computer. For example, you might create the file at *~/.gitignore_global* and add some rules to it.
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
2. Configure Git to use the exclude file *~/.gitignore_global* for all Git repositories.
|
||||
```shell
|
||||
$ git config --global core.excludesfile ~/.gitignore_global
|
||||
```
|
||||
|
||||
### Excluding local files without creating a *.gitignore* file
|
||||
|
||||
If you don't want to create a *.gitignore* file to share with others, you can create rules that are not committed with the repository. You can use this technique for locally-generated files that you don't expect other users to generate, such as files created by your editor.
|
||||
|
||||
Use your favorite text editor to open the file called *.git/info/exclude* within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
2. Navigate to the location of your Git repository.
|
||||
3. Using your favorite text editor, open the file *.git/info/exclude*.
|
||||
|
||||
### Further Reading
|
||||
|
||||
* [Ignoring files](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring) in the Pro Git book
|
||||
* [.gitignore](https://git-scm.com/docs/gitignore) in the man pages for Git
|
||||
* [A collection of useful *.gitignore* templates](https://github.com/github/gitignore) in the github/gitignore repository
|
||||
* [gitignore.io](https://www.gitignore.io/) site
|
||||
@@ -12,6 +12,9 @@ redirect_from:
|
||||
- /categories/53/articles/
|
||||
- /categories/setup/
|
||||
- /categories/getting-started-with-github
|
||||
- /categories/19/articles/
|
||||
- /categories/using-git
|
||||
- /github/using-git
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
@@ -68,7 +71,6 @@ topics:
|
||||
{% link_in_list /access-permissions-on-github %}
|
||||
{% link_in_list /faq-about-changes-to-githubs-plans %}
|
||||
|
||||
|
||||
{% topic_link_in_list /signing-up-for-github %}
|
||||
{% link_in_list /signing-up-for-a-new-github-account %}
|
||||
{% link_in_list /verifying-your-email-address %}
|
||||
@@ -89,4 +91,25 @@ topics:
|
||||
{% link_in_list /saving-repositories-with-stars %}
|
||||
{% link_in_list /following-people %}
|
||||
|
||||
{% topic_link_in_list /getting-started-with-git %}
|
||||
{% link_in_list /setting-your-username-in-git %}
|
||||
{% link_in_list /caching-your-github-credentials-in-git %}
|
||||
{% link_in_list /why-is-git-always-asking-for-my-password %}
|
||||
{% link_in_list /updating-credentials-from-the-macos-keychain %}
|
||||
{% link_in_list /git-workflows %}
|
||||
{% link_in_list /about-remote-repositories %}
|
||||
{% link_in_list /managing-remote-repositories %}
|
||||
{% link_in_list /associating-text-editors-with-git %}
|
||||
{% link_in_list /configuring-git-to-handle-line-endings %}
|
||||
{% link_in_list /ignoring-files %}
|
||||
|
||||
{% topic_link_in_list /using-git %}
|
||||
{% link_in_list /pushing-commits-to-a-remote-repository %}
|
||||
{% link_in_list /getting-changes-from-a-remote-repository %}
|
||||
{% link_in_list /dealing-with-non-fast-forward-errors %}
|
||||
{% link_in_list /splitting-a-subfolder-out-into-a-new-repository %}
|
||||
{% link_in_list /about-git-subtree-merges %}
|
||||
{% link_in_list /about-git-rebase %}
|
||||
{% link_in_list /using-git-rebase-on-the-command-line %}
|
||||
{% link_in_list /resolving-merge-conflicts-after-a-git-rebase %}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
---
|
||||
title: Managing remote repositories
|
||||
intro: 'Learn to work with your local repositories on your computer and remote repositories hosted on {% data variables.product.product_name %}.'
|
||||
redirect_from:
|
||||
- /categories/18/articles/
|
||||
- /remotes/
|
||||
- /categories/managing-remotes/
|
||||
- /articles/managing-remote-repositories
|
||||
- /articles/adding-a-remote
|
||||
- /github/using-git/adding-a-remote
|
||||
- /articles/changing-a-remote-s-url
|
||||
- /articles/changing-a-remotes-url
|
||||
- /github/using-git/changing-a-remotes-url
|
||||
- /articles/renaming-a-remote
|
||||
- /github/using-git/renaming-a-remote
|
||||
- /articles/removing-a-remote
|
||||
- /github/using-git/removing-a-remote
|
||||
- /github/using-git/managing-remote-repositories
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
### Adding a remote repository
|
||||
|
||||
To add a new remote, use the `git remote add` command on the terminal, in the directory your repository is stored at.
|
||||
|
||||
The `git remote add` command takes two arguments:
|
||||
* A remote name, for example, `origin`
|
||||
* A remote URL, for example, `https://{% data variables.command_line.backticks %}/user/repo.git`
|
||||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
$ git remote add origin https://{% data variables.command_line.codeblock %}/<em>user</em>/<em>repo</em>.git
|
||||
# Set a new remote
|
||||
|
||||
$ git remote -v
|
||||
# Verify new remote
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>user</em>/<em>repo</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>user</em>/<em>repo</em>.git (push)
|
||||
```
|
||||
|
||||
For more information on which URL to use, see "[About remote repositories](/github/getting-started-with-github/about-remote-repositories)."
|
||||
|
||||
#### Troubleshooting: Remote origin already exists
|
||||
|
||||
This error means you've tried to add a remote with a name that already exists in your local repository.
|
||||
|
||||
```shell
|
||||
$ git remote add origin https://{% data variables.command_line.codeblock %}/octocat/Spoon-Knife.git
|
||||
> fatal: remote origin already exists.
|
||||
```
|
||||
|
||||
To fix this, you can:
|
||||
* Use a different name for the new remote
|
||||
* Rename the existing remote repository
|
||||
* Delete the existing remote repository
|
||||
|
||||
### Changing a remote repository's URL
|
||||
|
||||
The `git remote set-url` command changes an existing remote repository URL.
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tip:** For information on the difference between HTTPS and SSH URLs, see "[About remote repositories](/github/getting-started-with-github/about-remote-repositories)."
|
||||
|
||||
{% endtip %}
|
||||
|
||||
The `git remote set-url` command takes two arguments:
|
||||
|
||||
* An existing remote name. For example, `origin` or `upstream` are two common choices.
|
||||
* A new URL for the remote. For example:
|
||||
* If you're updating to use HTTPS, your URL might look like:
|
||||
```shell
|
||||
https://{% data variables.command_line.backticks %}/<em>USERNAME</em>/<em>REPOSITORY</em>.git
|
||||
```
|
||||
* If you're updating to use SSH, your URL might look like:
|
||||
```shell
|
||||
git@{% data variables.command_line.codeblock %}:<em>USERNAME</em>/<em>REPOSITORY</em>.git
|
||||
```
|
||||
|
||||
#### Switching remote URLs from SSH to HTTPS
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
2. Change the current working directory to your local project.
|
||||
3. List your existing remotes in order to get the name of the remote you want to change.
|
||||
```shell
|
||||
$ git remote -v
|
||||
> origin git@{% data variables.command_line.codeblock %}:<em>USERNAME/REPOSITORY</em>.git (fetch)
|
||||
> origin git@{% data variables.command_line.codeblock %}:<em>USERNAME/REPOSITORY</em>.git (push)
|
||||
```
|
||||
4. Change your remote's URL from SSH to HTTPS with the `git remote set-url` command.
|
||||
```shell
|
||||
$ git remote set-url origin https://{% data variables.command_line.codeblock %}/<em>USERNAME</em>/<em>REPOSITORY</em>.git
|
||||
```
|
||||
5. Verify that the remote URL has changed.
|
||||
```shell
|
||||
$ git remote -v
|
||||
# Verify new remote URL
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY</em>.git (push)
|
||||
```
|
||||
|
||||
The next time you `git fetch`, `git pull`, or `git push` to the remote repository, you'll be asked for your GitHub username and password. {% data reusables.user_settings.password-authentication-deprecation %}
|
||||
|
||||
You can [use a credential helper](/github/getting-started-with-github/caching-your-github-credentials-in-git) so Git will remember your GitHub username and personal access token every time it talks to GitHub.
|
||||
|
||||
#### Switching remote URLs from HTTPS to SSH
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
2. Change the current working directory to your local project.
|
||||
3. List your existing remotes in order to get the name of the remote you want to change.
|
||||
```shell
|
||||
$ git remote -v
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY</em>.git (push)
|
||||
```
|
||||
4. Change your remote's URL from HTTPS to SSH with the `git remote set-url` command.
|
||||
```shell
|
||||
$ git remote set-url origin git@{% data variables.command_line.codeblock %}:<em>USERNAME</em>/<em>REPOSITORY</em>.git
|
||||
```
|
||||
5. Verify that the remote URL has changed.
|
||||
```shell
|
||||
$ git remote -v
|
||||
# Verify new remote URL
|
||||
> origin git@{% data variables.command_line.codeblock %}:<em>USERNAME/REPOSITORY</em>.git (fetch)
|
||||
> origin git@{% data variables.command_line.codeblock %}:<em>USERNAME/REPOSITORY</em>.git (push)
|
||||
```
|
||||
|
||||
#### Troubleshooting: No such remote '[name]'
|
||||
|
||||
This error means that the remote you tried to change doesn't exist:
|
||||
|
||||
```shell
|
||||
$ git remote set-url sofake https://{% data variables.command_line.codeblock %}/octocat/Spoon-Knife
|
||||
> fatal: No such remote 'sofake'
|
||||
```
|
||||
|
||||
Check that you've correctly typed the remote name.
|
||||
|
||||
### Renaming a remote repository
|
||||
|
||||
Use the `git remote rename` command to rename an existing remote.
|
||||
|
||||
The `git remote rename` command takes two arguments:
|
||||
* An existing remote name, for example, `origin`
|
||||
* A new name for the remote, for example, `destination`
|
||||
|
||||
### Example
|
||||
|
||||
These examples assume you're [cloning using HTTPS](/github/getting-started-with-github/about-remote-repositories/#cloning-with-https-urls), which is recommended.
|
||||
|
||||
```shell
|
||||
$ git remote -v
|
||||
# View existing remotes
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER</em>/<em>REPOSITORY</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER</em>/<em>REPOSITORY</em>.git (push)
|
||||
|
||||
$ git remote rename origin destination
|
||||
# Change remote name from 'origin' to 'destination'
|
||||
|
||||
$ git remote -v
|
||||
# Verify remote's new name
|
||||
> destination https://{% data variables.command_line.codeblock %}/<em>OWNER</em>/<em>REPOSITORY</em>.git (fetch)
|
||||
> destination https://{% data variables.command_line.codeblock %}/<em>OWNER</em>/<em>REPOSITORY</em>.git (push)
|
||||
```
|
||||
|
||||
#### Troubleshooting: Could not rename config section 'remote.[old name]' to 'remote.[new name]'
|
||||
|
||||
This error means that the remote you tried the old remote name you typed doesn't exist.
|
||||
|
||||
You can check which remotes currently exist with the `git remote -v` command:
|
||||
|
||||
```shell
|
||||
$ git remote -v
|
||||
# View existing remotes
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER</em>/<em>REPOSITORY</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER</em>/<em>REPOSITORY</em>.git (push)
|
||||
```
|
||||
|
||||
#### Troubleshooting: Remote [new name] already exists
|
||||
|
||||
This error means that the remote name you want to use already exists. To solve this, either use a different remote name, or rename the original remote.
|
||||
|
||||
### Removing a remote repository
|
||||
|
||||
Use the `git remote rm` command to remove a remote URL from your repository.
|
||||
|
||||
The `git remote rm` command takes one argument:
|
||||
* A remote name, for example, `destination`
|
||||
|
||||
### Example
|
||||
|
||||
These examples assume you're [cloning using HTTPS](/github/getting-started-with-github/about-remote-repositories/#cloning-with-https-urls), which is recommended.
|
||||
|
||||
```shell
|
||||
$ git remote -v
|
||||
# View current remotes
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER/REPOSITORY</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER/REPOSITORY</em>.git (push)
|
||||
> destination https://{% data variables.command_line.codeblock %}/<em>FORKER/REPOSITORY</em>.git (fetch)
|
||||
> destination https://{% data variables.command_line.codeblock %}/<em>FORKER/REPOSITORY</em>.git (push)
|
||||
|
||||
$ git remote rm destination
|
||||
# Remove remote
|
||||
$ git remote -v
|
||||
# Verify it's gone
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER/REPOSITORY</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>OWNER/REPOSITORY</em>.git (push)
|
||||
```
|
||||
|
||||
{% warning %}
|
||||
|
||||
**Note**: `git remote rm` does not delete the remote repository from the server. It simply
|
||||
removes the remote and its references from your local repository.
|
||||
|
||||
{% endwarning %}
|
||||
|
||||
#### Troubleshooting: Could not remove config section 'remote.[name]'
|
||||
|
||||
This error means that the remote you tried to delete doesn't exist:
|
||||
|
||||
```shell
|
||||
$ git remote rm sofake
|
||||
> error: Could not remove config section 'remote.sofake'
|
||||
```
|
||||
|
||||
Check that you've correctly typed the remote name.
|
||||
|
||||
### Further reading
|
||||
|
||||
- "[Working with Remotes" from the _Pro Git_ book](https://git-scm.com/book/en/Git-Basics-Working-with-Remotes)
|
||||
@@ -0,0 +1,115 @@
|
||||
---
|
||||
title: Pushing commits to a remote repository
|
||||
intro: Use `git push` to push commits made on your local branch to a remote repository.
|
||||
redirect_from:
|
||||
- /articles/pushing-to-a-remote/
|
||||
- /articles/pushing-commits-to-a-remote-repository
|
||||
- /github/using-git/pushing-commits-to-a-remote-repository
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
The `git push` command takes two arguments:
|
||||
|
||||
* A remote name, for example, `origin`
|
||||
* A branch name, for example, `main`
|
||||
|
||||
For example:
|
||||
|
||||
```shell
|
||||
git push <em> <REMOTENAME> <BRANCHNAME> </em>
|
||||
```
|
||||
|
||||
As an example, you usually run `git push origin main` to push your local changes
|
||||
to your online repository.
|
||||
|
||||
### Renaming branches
|
||||
|
||||
To rename a branch, you'd use the same `git push` command, but you would add
|
||||
one more argument: the name of the new branch. For example:
|
||||
|
||||
```shell
|
||||
git push <em> <REMOTENAME> <LOCALBRANCHNAME></em>:<em><REMOTEBRANCHNAME> </em>
|
||||
```
|
||||
|
||||
This pushes the `LOCALBRANCHNAME` to your `REMOTENAME`, but it is renamed to `REMOTEBRANCHNAME`.
|
||||
|
||||
### Dealing with "non-fast-forward" errors
|
||||
|
||||
If your local copy of a repository is out of sync with, or "behind," the upstream
|
||||
repository you're pushing to, you'll get a message saying `non-fast-forward updates were rejected`.
|
||||
This means that you must retrieve, or "fetch," the upstream changes, before
|
||||
you are able to push your local changes.
|
||||
|
||||
For more information on this error, see "[Dealing with non-fast-forward errors](/github/getting-started-with-github/dealing-with-non-fast-forward-errors)."
|
||||
|
||||
### Pushing tags
|
||||
|
||||
By default, and without additional parameters, `git push` sends all matching branches
|
||||
that have the same names as remote branches.
|
||||
|
||||
To push a single tag, you can issue the same command as pushing a branch:
|
||||
|
||||
```shell
|
||||
git push <em> <REMOTENAME> <TAGNAME> </em>
|
||||
```
|
||||
|
||||
To push all your tags, you can type the command:
|
||||
|
||||
```shell
|
||||
git push <em> <REMOTENAME></em> --tags
|
||||
```
|
||||
|
||||
### Deleting a remote branch or tag
|
||||
|
||||
The syntax to delete a branch is a bit arcane at first glance:
|
||||
|
||||
```shell
|
||||
git push <em> <REMOTENAME></em> :<em><BRANCHNAME> </em>
|
||||
```
|
||||
|
||||
Note that there is a space before the colon. The command resembles the same steps
|
||||
you'd take to rename a branch. However, here, you're telling Git to push _nothing_
|
||||
into `BRANCHNAME` on `REMOTENAME`. Because of this, `git push` deletes the branch
|
||||
on the remote repository.
|
||||
|
||||
### Remotes and forks
|
||||
|
||||
You might already know that [you can "fork" repositories](https://guides.github.com/overviews/forking/) on GitHub.
|
||||
|
||||
When you clone a repository you own, you provide it with a remote URL that tells
|
||||
Git where to fetch and push updates. If you want to collaborate with the original
|
||||
repository, you'd add a new remote URL, typically called `upstream`, to
|
||||
your local Git clone:
|
||||
|
||||
```shell
|
||||
git remote add upstream <em> <THEIR_REMOTE_URL> </em>
|
||||
```
|
||||
|
||||
Now, you can fetch updates and branches from *their* fork:
|
||||
|
||||
```shell
|
||||
git fetch upstream
|
||||
# Grab the upstream remote's branches
|
||||
> remote: Counting objects: 75, done.
|
||||
> remote: Compressing objects: 100% (53/53), done.
|
||||
> remote: Total 62 (delta 27), reused 44 (delta 9)
|
||||
> Unpacking objects: 100% (62/62), done.
|
||||
> From https://{% data variables.command_line.codeblock %}/<em>octocat</em>/<em>repo</em>
|
||||
> * [new branch] main -> upstream/main
|
||||
```
|
||||
|
||||
When you're done making local changes, you can push your local branch to GitHub
|
||||
and [initiate a pull request](/articles/about-pull-requests).
|
||||
|
||||
For more information on working with forks, see "[Syncing a fork](/articles/syncing-a-fork)".
|
||||
|
||||
### Further reading
|
||||
|
||||
- [The "Remotes" chapter from the "Pro Git" book](https://git-scm.com/book/ch5-2.html)
|
||||
- [`git remote` man page](https://git-scm.com/docs/git-remote.html)
|
||||
- "[Git cheatsheet](/articles/git-cheatsheet)"
|
||||
- "[Git workflows](/github/getting-started-with-github/git-workflows)"
|
||||
- "[Git Handbook](https://guides.github.com/introduction/git-handbook/)"
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: Resolving merge conflicts after a Git rebase
|
||||
intro: 'When you perform a `git rebase` operation, you''re typically moving commits around. Because of this, you might get into a situation where a merge conflict is introduced. That means that two of your commits modified the same line in the same file, and Git doesn''t know which change to apply.'
|
||||
redirect_from:
|
||||
- /articles/resolving-merge-conflicts-after-a-git-rebase
|
||||
- /github/using-git/resolving-merge-conflicts-after-a-git-rebase
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
|
||||
After you reorder and manipulate commits using `git rebase`, should a merge conflict occur, Git will tell you so with the following message printed to the terminal:
|
||||
|
||||
```shell
|
||||
error: could not apply fa39187... something to add to patch A
|
||||
|
||||
When you have resolved this problem, run "git rebase --continue".
|
||||
If you prefer to skip this patch, run "git rebase --skip" instead.
|
||||
To check out the original branch and stop rebasing, run "git rebase --abort".
|
||||
Could not apply fa39187f3c3dfd2ab5faa38ac01cf3de7ce2e841... Change fake file
|
||||
```
|
||||
|
||||
Here, Git is telling you which commit is causing the conflict (`fa39187`). You're given three choices:
|
||||
|
||||
* You can run `git rebase --abort` to completely undo the rebase. Git will return you to your branch's state as it was before `git rebase` was called.
|
||||
* You can run `git rebase --skip` to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option.
|
||||
* You can fix the conflict.
|
||||
|
||||
To fix the conflict, you can follow [the standard procedures for resolving merge conflicts from the command line](/articles/resolving-a-merge-conflict-using-the-command-line). When you're finished, you'll need to call `git rebase --continue` in order for Git to continue processing the rest of the rebase.
|
||||
@@ -36,7 +36,7 @@ If you don't need to work with files locally, {% data variables.product.product_
|
||||
### Setting up Git
|
||||
|
||||
1. [Download and install the latest version of Git](https://git-scm.com/downloads).
|
||||
2. [Set your username in Git](/articles/setting-your-username-in-git).
|
||||
2. [Set your username in Git](/github/getting-started-with-github/setting-your-username-in-git).
|
||||
3. [Set your commit email address in Git](/articles/setting-your-commit-email-address).
|
||||
|
||||
### Next steps: Authenticating with {% data variables.product.prodname_dotcom %} from Git
|
||||
@@ -45,11 +45,11 @@ When you connect to a {% data variables.product.product_name %} repository from
|
||||
|
||||
#### Connecting over HTTPS (recommended)
|
||||
|
||||
If you [clone with HTTPS](/articles/which-remote-url-should-i-use/#cloning-with-https-urls), you can [cache your {% data variables.product.prodname_dotcom %} credentials in Git](/github/using-git/caching-your-github-credentials-in-git) using a credential helper.
|
||||
If you [clone with HTTPS](/github/getting-started-with-github/about-remote-repositories/#cloning-with-https-urls), you can [cache your {% data variables.product.prodname_dotcom %} credentials in Git](/github/getting-started-with-github/caching-your-github-credentials-in-git) using a credential helper.
|
||||
|
||||
#### Connecting over SSH
|
||||
|
||||
If you [clone with SSH](/articles/which-remote-url-should-i-use#cloning-with-ssh-urls), you must [generate SSH keys](/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) on each computer you use to push or pull from {% data variables.product.product_name %}.
|
||||
If you [clone with SSH](/github/getting-started-with-github/about-remote-repositories/#cloning-with-ssh-urls), you must [generate SSH keys](/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) on each computer you use to push or pull from {% data variables.product.product_name %}.
|
||||
|
||||
### Celebrate
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
title: Setting your username in Git
|
||||
intro: 'Git uses a username to associate commits with an identity. The Git username is not the same as your {% data variables.product.product_name %} username.'
|
||||
redirect_from:
|
||||
- /articles/setting-your-username-in-git
|
||||
- /github/using-git/setting-your-username-in-git
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
You can change the name that is associated with your Git commits using the `git config` command. The new name you set will be visible in any future commits you push to {% data variables.product.product_name %} from the command line. If you'd like to keep your real name private, you can use any text as your Git username.
|
||||
|
||||
Changing the name associated with your Git commits using `git config` will only affect future commits and will not change the name used for past commits.
|
||||
|
||||
### Setting your Git username for *every* repository on your computer
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
|
||||
2. {% data reusables.user_settings.set_your_git_username %}
|
||||
```shell
|
||||
$ git config --global user.name "<em>Mona Lisa</em>"
|
||||
```
|
||||
|
||||
3. {% data reusables.user_settings.confirm_git_username_correct %}
|
||||
```shell
|
||||
$ git config --global user.name
|
||||
> Mona Lisa
|
||||
```
|
||||
|
||||
### Setting your Git username for a single repository
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
|
||||
2. Change the current working directory to the local repository where you want to configure the name that is associated with your Git commits.
|
||||
|
||||
3. {% data reusables.user_settings.set_your_git_username %}
|
||||
```shell
|
||||
$ git config user.name "<em>Mona Lisa</em>"
|
||||
```
|
||||
|
||||
3. {% data reusables.user_settings.confirm_git_username_correct %}
|
||||
```shell
|
||||
$ git config user.name
|
||||
> Mona Lisa
|
||||
```
|
||||
|
||||
### Further reading
|
||||
|
||||
- "[Setting your commit email address](/articles/setting-your-commit-email-address)"
|
||||
- ["Git Configuration" from the _Pro Git_ book](https://git-scm.com/book/en/Customizing-Git-Git-Configuration)
|
||||
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: Splitting a subfolder out into a new repository
|
||||
redirect_from:
|
||||
- /articles/splitting-a-subpath-out-into-a-new-repository/
|
||||
- /articles/splitting-a-subfolder-out-into-a-new-repository
|
||||
- /github/using-git/splitting-a-subfolder-out-into-a-new-repository
|
||||
intro: You can turn a folder within a Git repository into a brand new repository.
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
If you create a new clone of the repository, you won't lose any of your Git history or changes when you split a folder into a separate repository.
|
||||
|
||||
{% data reusables.command_line.open_the_multi_os_terminal %}
|
||||
2. Change the current working directory to the location where you want to create your new repository.
|
||||
3. Clone the repository that contains the subfolder.
|
||||
```shell
|
||||
$ git clone https://{% data variables.command_line.codeblock %}/<em>USERNAME</em>/<em>REPOSITORY-NAME</em>
|
||||
```
|
||||
4. Change the current working directory to your cloned repository.
|
||||
```shell
|
||||
$ cd <em>REPOSITORY-NAME</em>
|
||||
```
|
||||
5. To filter out the subfolder from the rest of the files in the repository, run [`git filter-branch`](https://git-scm.com/docs/git-filter-branch), supplying this information:
|
||||
- `FOLDER-NAME`: The folder within your project that you'd like to create a separate repository from.
|
||||
|
||||
{% windows %}
|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tip:** Windows users should use `/` to delimit folders.
|
||||
|
||||
{% endtip %}
|
||||
|
||||
{% endwindows %}
|
||||
- `BRANCH-NAME`: The default branch for your current project, for example, `main` or `gh-pages`.
|
||||
```shell
|
||||
$ git filter-branch --prune-empty --subdirectory-filter <em>FOLDER-NAME BRANCH-NAME</em>
|
||||
# Filter the specified branch in your directory and remove empty commits
|
||||
> Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (89/89)
|
||||
> Ref 'refs/heads/<em>BRANCH-NAME</em>' was rewritten
|
||||
```
|
||||
The repository should now only contain the files that were in your subfolder.
|
||||
|
||||
6. [Create a new repository](/articles/creating-a-new-repository/) on {% data variables.product.product_name %}.
|
||||
7. At the top of your new {% data variables.product.product_name %} repository's Quick Setup page, click {% octicon "clippy" aria-label="The copy to clipboard icon" %} to copy the remote repository URL.
|
||||

|
||||
|
||||
{% tip %}
|
||||
|
||||
**Tip:** For information on the difference between HTTPS and SSH URLs, see "[About remote repositories](/github/getting-started-with-github/about-remote-repositories)."
|
||||
|
||||
{% endtip %}
|
||||
|
||||
8. Check the existing remote name for your repository. For example, `origin` or `upstream` are two common choices.
|
||||
```shell
|
||||
$ git remote -v
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY-NAME</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/REPOSITORY-NAME</em>.git (push)
|
||||
```
|
||||
|
||||
9. Set up a new remote URL for your new repository using the existing remote name and the remote repository URL you copied in step 7.
|
||||
```shell
|
||||
git remote set-url origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git
|
||||
```
|
||||
10. Verify that the remote URL has changed with your new repository name.
|
||||
```shell
|
||||
$ git remote -v
|
||||
# Verify new remote URL
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git (fetch)
|
||||
> origin https://{% data variables.command_line.codeblock %}/<em>USERNAME/NEW-REPOSITORY-NAME</em>.git (push)
|
||||
```
|
||||
11. Push your changes to the new repository on {% data variables.product.product_name %}.
|
||||
```shell
|
||||
git push -u origin <em>BRANCH-NAME</em>
|
||||
```
|
||||
@@ -0,0 +1,39 @@
|
||||
---
|
||||
title: Updating credentials from the macOS Keychain
|
||||
intro: 'You''ll need to update your saved credentials in the `git-credential-osxkeychain` helper if you change your{% if currentVersion != "github-ae@latest" %} username, password, or{% endif %} personal access token on {% data variables.product.product_name %}.'
|
||||
redirect_from:
|
||||
- /articles/updating-credentials-from-the-osx-keychain
|
||||
- /github/using-git/updating-credentials-from-the-osx-keychain
|
||||
- /github/using-git/updating-credentials-from-the-macos-keychain
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
{% data reusables.user_settings.password-authentication-deprecation %}
|
||||
|
||||
### Updating your credentials via Keychain Access
|
||||
|
||||
1. Click on the Spotlight icon (magnifying glass) on the right side of the menu bar. Type `Keychain access` then press the Enter key to launch the app.
|
||||

|
||||
2. In Keychain Access, search for **{% data variables.command_line.backticks %}**.
|
||||
3. Find the "internet password" entry for `{% data variables.command_line.backticks %}`.
|
||||
4. Edit or delete the entry accordingly.
|
||||
|
||||
### Deleting your credentials via the command line
|
||||
|
||||
Through the command line, you can use the credential helper directly to erase the keychain entry.
|
||||
|
||||
```shell
|
||||
$ git credential-osxkeychain erase
|
||||
host={% data variables.command_line.codeblock %}
|
||||
protocol=https
|
||||
> <em>[Press Return]</em>
|
||||
```
|
||||
|
||||
If it's successful, nothing will print out. To test that it works, try and clone a private repository from {% data variables.product.product_location %}. If you are prompted for a password, the keychain entry was deleted.
|
||||
|
||||
### Further reading
|
||||
|
||||
- "[Caching your {% data variables.product.prodname_dotcom %} credentials in Git](/github/getting-started-with-github/caching-your-github-credentials-in-git/)"
|
||||
@@ -0,0 +1,143 @@
|
||||
---
|
||||
title: Using Git rebase on the command line
|
||||
redirect_from:
|
||||
- /articles/using-git-rebase/
|
||||
- /articles/using-git-rebase-on-the-command-line
|
||||
- /github/using-git/using-git-rebase-on-the-command-line
|
||||
intro: Here's a short tutorial on using `git rebase` on the command line.
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
In this example, we will cover all of the `git rebase` commands available, except for `exec`.
|
||||
|
||||
We'll start our rebase by entering `git rebase --interactive HEAD~7` on the terminal. Our favorite text editor will display the following lines:
|
||||
|
||||
```
|
||||
pick 1fc6c95 Patch A
|
||||
pick 6b2481b Patch B
|
||||
pick dd1475d something I want to split
|
||||
pick c619268 A fix for Patch B
|
||||
pick fa39187 something to add to patch A
|
||||
pick 4ca2acc i cant' typ goods
|
||||
pick 7b36971 something to move before patch B
|
||||
```
|
||||
|
||||
In this example, we're going to:
|
||||
|
||||
* Squash the fifth commit (`fa39187`) into the `"Patch A"` commit (`1fc6c95`), using `squash`.
|
||||
* Move the last commit (`7b36971`) up before the `"Patch B"` commit (`6b2481b`), and keep it as `pick`.
|
||||
* Merge the `"A fix for Patch B"` commit (`c619268`) into the `"Patch B"` commit (`6b2481b`), and disregard the commit message using `fixup`.
|
||||
* Split the third commit (`dd1475d`) into two smaller commits, using `edit`.
|
||||
* Fix the commit message of the misspelled commit (`4ca2acc`), using `reword`.
|
||||
|
||||
Phew! This sounds like a lot of work, but by taking it one step at a time, we can easily make those changes.
|
||||
|
||||
To start, we'll need to modify the commands in the file to look like this:
|
||||
|
||||
```
|
||||
pick 1fc6c95 Patch A
|
||||
squash fa39187 something to add to patch A
|
||||
pick 7b36971 something to move before patch B
|
||||
pick 6b2481b Patch B
|
||||
fixup c619268 A fix for Patch B
|
||||
edit dd1475d something I want to split
|
||||
reword 4ca2acc i cant' typ goods
|
||||
```
|
||||
|
||||
We've changed each line's command from `pick` to the command we're interested in.
|
||||
|
||||
Now, save and close the editor; this will start the interactive rebase.
|
||||
|
||||
Git skips the first rebase command, `pick 1fc6c95`, since it doesn't need to do anything. It goes to the next command, `squash fa39187`. Since this operation requires your input, Git opens your text editor once again. The file it opens up looks something like this:
|
||||
|
||||
```
|
||||
# This is a combination of two commits.
|
||||
# The first commit's message is:
|
||||
|
||||
Patch A
|
||||
|
||||
# This is the 2nd commit message:
|
||||
|
||||
something to add to patch A
|
||||
|
||||
# Please enter the commit message for your changes. Lines starting
|
||||
# with '#' will be ignored, and an empty message aborts the commit.
|
||||
# Not currently on any branch.
|
||||
# Changes to be committed:
|
||||
# (use "git reset HEAD <file>..." to unstage)
|
||||
#
|
||||
# modified: a
|
||||
#
|
||||
```
|
||||
|
||||
This file is Git's way of saying, "Hey, here's what I'm about to do with this `squash`." It lists the first commit's message (`"Patch A"`), and the second commit's message (`"something to add to patch A"`). If you're happy with these commit messages, you can save the file, and close the editor. Otherwise, you have the option of changing the commit message by simply changing the text.
|
||||
|
||||
When the editor is closed, the rebase continues:
|
||||
|
||||
```
|
||||
pick 1fc6c95 Patch A
|
||||
squash fa39187 something to add to patch A
|
||||
pick 7b36971 something to move before patch B
|
||||
pick 6b2481b Patch B
|
||||
fixup c619268 A fix for Patch B
|
||||
edit dd1475d something I want to split
|
||||
reword 4ca2acc i cant' typ goods
|
||||
```
|
||||
|
||||
Git processes the two `pick` commands (for `pick 7b36971` and `pick 6b2481b`). It *also* processes the `fixup` command (`fixup c619268`), since it doesn't require any interaction. `fixup` merges the changes from `c619268` into the commit before it, `6b2481b`. Both changes will have the same commit message: `"Patch B"`.
|
||||
|
||||
Git gets to the `edit dd1475d` operation, stops, and prints the following message to the terminal:
|
||||
|
||||
```shell
|
||||
You can amend the commit now, with
|
||||
|
||||
git commit --amend
|
||||
|
||||
Once you are satisfied with your changes, run
|
||||
|
||||
git rebase --continue
|
||||
```
|
||||
|
||||
At this point, you can edit any of the files in your project to make any additional changes. For each change you make, you'll need to perform a new commit, and you can do that by entering the `git commit --amend` command. When you're finished making all your changes, you can run `git rebase --continue`.
|
||||
|
||||
Git then gets to the `reword 4ca2acc` command. It opens up your text editor one more time, and presents the following information:
|
||||
|
||||
```
|
||||
i cant' typ goods
|
||||
|
||||
# Please enter the commit message for your changes. Lines starting
|
||||
# with '#' will be ignored, and an empty message aborts the commit.
|
||||
# Not currently on any branch.
|
||||
# Changes to be committed:
|
||||
# (use "git reset HEAD^1 <file>..." to unstage)
|
||||
#
|
||||
# modified: a
|
||||
#
|
||||
```
|
||||
|
||||
As before, Git is showing the commit message for you to edit. You can change the text (`"i cant' typ goods"`), save the file, and close the editor. Git will finish the rebase and return you to the terminal.
|
||||
|
||||
### Pushing rebased code to GitHub
|
||||
|
||||
Since you've altered Git history, the usual `git push origin` **will not** work. You'll need to modify the command by "force-pushing" your latest changes:
|
||||
|
||||
```shell
|
||||
# Don't override changes
|
||||
$ git push origin main --force-with-lease
|
||||
|
||||
# Override changes
|
||||
$ git push origin main --force
|
||||
```
|
||||
|
||||
{% warning %}
|
||||
|
||||
Force pushing has serious implications because it changes the historical sequence of commits for the branch. Use it with caution, especially if your repository is being accessed by multiple people.
|
||||
|
||||
{% endwarning %}
|
||||
|
||||
### Further reading
|
||||
|
||||
* "[Resolving merge conflicts after a Git rebase](/github/getting-started-with-github/resolving-merge-conflicts-after-a-git-rebase)"
|
||||
17
content/github/getting-started-with-github/using-git.md
Normal file
17
content/github/getting-started-with-github/using-git.md
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: Using Git
|
||||
intro: ''
|
||||
mapTopic: true
|
||||
redirect_from:
|
||||
- /articles/using-common-git-commands
|
||||
- /github/using-git/using-common-git-commands
|
||||
- /github/using-git/using-advanced-git-commands
|
||||
- /categories/52/articles/
|
||||
- /categories/advanced-git/
|
||||
- /articles/using-advanced-git-commands
|
||||
- /github/using-git/changing-author-info
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
@@ -0,0 +1,23 @@
|
||||
---
|
||||
title: Why is Git always asking for my password?
|
||||
intro: 'If Git prompts you for a username and password every time you try to interact with GitHub, you''re probably using the HTTPS clone URL for your repository.'
|
||||
redirect_from:
|
||||
- /articles/why-is-git-always-asking-for-my-password
|
||||
- /github/using-git/why-is-git-always-asking-for-my-password
|
||||
versions:
|
||||
free-pro-team: '*'
|
||||
enterprise-server: '*'
|
||||
github-ae: '*'
|
||||
---
|
||||
|
||||
Using an HTTPS remote URL has some advantages compared with using SSH. It's easier to set up than SSH, and usually works through strict firewalls and proxies. However, it also prompts you to enter your {% data variables.product.product_name %} credentials every time you pull or push a repository.
|
||||
|
||||
{% data reusables.user_settings.password-authentication-deprecation %}
|
||||
|
||||
You can avoid being prompted for your password by configuring Git to [cache your credentials](/github/getting-started-with-github/caching-your-github-credentials-in-git) for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.
|
||||
|
||||
### Further reading
|
||||
|
||||
- "[About remote repositories](/github/getting-started-with-github/about-remote-repositories)."
|
||||
- "[About authentication to {% data variables.product.prodname_dotcom %}](/github/authenticating-to-github/about-authentication-to-github)"
|
||||
- "[Adding your SSH key to the ssh-agent](/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent)"
|
||||
Reference in New Issue
Block a user