Commit 7f92a5e8 authored by Afzaal Ahmad Zeeshan's avatar Afzaal Ahmad Zeeshan Committed by Marcel Amirault

Update start-using-git.md with upstream details

Added content to the Git guide explaining how
to work with forks and upstream repos.
parent b8bb12aa
...@@ -61,10 +61,12 @@ To verify that you entered your email correctly, type: ...@@ -61,10 +61,12 @@ To verify that you entered your email correctly, type:
git config --global user.email git config --global user.email
``` ```
You'll need to do this only once, since you are using the `--global` option. It tells You'll need to do this only once, since you are using the `--global` option. It
Git to always use this information for anything you do on that system. If you want tells Git to always use this information for anything you do on that system. If
to override this with a different username or email address for specific projects or repositories, you want to override this with a different username or email address for specific
you can run the command without the `--global` option when you’re in that project, and that will default to `--local`. You can read more on how Git manages configurations in the [Git Config](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) documentation. projects or repositories, you can run the command without the `--global` option
when you’re in that project, and that will default to `--local`. You can read more
on how Git manages configurations in the [Git Config](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) documentation.
## Check your information ## Check your information
...@@ -102,7 +104,10 @@ files to your local computer, automatically preserving the Git connection with t ...@@ -102,7 +104,10 @@ files to your local computer, automatically preserving the Git connection with t
remote repository. remote repository.
You can either clone it via HTTPS or [SSH](../ssh/README.md). If you chose to clone You can either clone it via HTTPS or [SSH](../ssh/README.md). If you chose to clone
it via HTTPS, you'll have to enter your credentials every time you pull and push. You can read more about credential storage in the [Git Credentials documentation](https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage). With SSH, you enter your credentials only once. it via HTTPS, you'll have to enter your credentials every time you pull and push.
You can read more about credential storage in the
[Git Credentials documentation](https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage).
With SSH, you enter your credentials only once.
You can find both paths (HTTPS and SSH) by navigating to your project's landing page You can find both paths (HTTPS and SSH) by navigating to your project's landing page
and clicking **Clone**. GitLab will prompt you with both paths, from which you can copy and clicking **Clone**. GitLab will prompt you with both paths, from which you can copy
...@@ -113,8 +118,8 @@ As an example, consider this repository path: ...@@ -113,8 +118,8 @@ As an example, consider this repository path:
- HTTPS: `https://gitlab.com/gitlab-org/gitlab.git` - HTTPS: `https://gitlab.com/gitlab-org/gitlab.git`
- SSH: `git@gitlab.com:gitlab-org/gitlab.git` - SSH: `git@gitlab.com:gitlab-org/gitlab.git`
To get started, open a terminal window in the directory you wish to clone the repository To get started, open a terminal window in the directory you wish to clone the
files into, and run one of the following commands. repository files into, and run one of the following commands.
Clone via HTTPS: Clone via HTTPS:
...@@ -134,9 +139,9 @@ on it locally. ...@@ -134,9 +139,9 @@ on it locally.
### Switch to the master branch ### Switch to the master branch
You are always in a branch when working with Git. The main branch is the master branch, You are always in a branch when working with Git. The main branch is the master
but you can use the same command to switch to a different branch by changing `master` branch, but you can use the same command to switch to a different branch by
to the branch name. changing `master` to the branch name.
```bash ```bash
git checkout master git checkout master
...@@ -145,10 +150,10 @@ git checkout master ...@@ -145,10 +150,10 @@ git checkout master
### Download the latest changes in the project ### Download the latest changes in the project
To work on an up-to-date copy of the project (it is important to do this every time To work on an up-to-date copy of the project (it is important to do this every time
you start working on a project), you `pull` to get all the changes made by users since you start working on a project), you `pull` to get all the changes made by users
the last time you cloned or pulled the project. Use `master` for the `<name-of-branch>` since the last time you cloned or pulled the project. Use `master` for the
to get the main branch code, or the branch name of the branch you are currently working `<name-of-branch>` to get the main branch code, or the branch name of the branch
in. you are currently working in.
```bash ```bash
git pull <REMOTE> <name-of-branch> git pull <REMOTE> <name-of-branch>
...@@ -156,10 +161,11 @@ git pull <REMOTE> <name-of-branch> ...@@ -156,10 +161,11 @@ git pull <REMOTE> <name-of-branch>
When you clone a repository, `REMOTE` is typically `origin`. This is where the When you clone a repository, `REMOTE` is typically `origin`. This is where the
repository was cloned from, and it indicates the SSH or HTTPS URL of the repository repository was cloned from, and it indicates the SSH or HTTPS URL of the repository
on the remote server. `<name-of-branch>` is usually `master`, but it may be any existing on the remote server. `<name-of-branch>` is usually `master`, but it may be any
branch. You can create additional named remotes and branches as necessary. existing branch. You can create additional named remotes and branches as necessary.
You can learn more on how Git manages remote repositories in the [Git Remote documentation](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes). You can learn more on how Git manages remote repositories in the
[Git Remote documentation](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes).
### View your remote repositories ### View your remote repositories
...@@ -184,9 +190,9 @@ so use something easy to remember and type. ...@@ -184,9 +190,9 @@ so use something easy to remember and type.
### Create a branch ### Create a branch
To create a new branch, to work from without affecting the `master` branch, type the To create a new branch, to work from without affecting the `master` branch, type
following (spaces won't be recognized in the branch name, so you will need to use a the following (spaces won't be recognized in the branch name, so you will need to
hyphen or underscore): use a hyphen or underscore):
```bash ```bash
git checkout -b <name-of-branch> git checkout -b <name-of-branch>
...@@ -245,6 +251,10 @@ The `.` character means _all file changes in the current directory and all subdi ...@@ -245,6 +251,10 @@ The `.` character means _all file changes in the current directory and all subdi
### Send changes to GitLab.com ### Send changes to GitLab.com
NOTE: **Note:**
To create a merge request from a fork to an upstream repository, see the
[forking workflow](../user/project/repository/forking_workflow.md)
To push all local commits (saved changes) to the remote repository: To push all local commits (saved changes) to the remote repository:
```bash ```bash
...@@ -301,6 +311,21 @@ git checkout <name-of-branch> ...@@ -301,6 +311,21 @@ git checkout <name-of-branch>
git merge master git merge master
``` ```
### Synchronize changes in a forked repository with the upstream
[Forking a repository](../user/project/repository/forking_workflow.md lets you create
a copy of a repository in your namespace. Changes made to your copy of the repository
are not synchronized automatically with the original.
Your local fork (copy) contains changes made by you only, so to keep the project
in sync with the original project, you need to `pull` from the original repository.
You must [create a link to the remote repository](#add-a-remote-repository) to pull
changes from the original repository. It is common to call this remote the `upstream`.
You can now use the `upstream` as a [`<remote>` to `pull` new updates](#download-the-latest-changes-in-the-project)
from the original repository, and use the `origin`
to [push local changes](#send-changes-to-gitlabcom) and create merge requests.
<!-- ## Troubleshooting <!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues Include any troubleshooting steps that you can foresee. If you know beforehand what issues
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment