Skip to content

Instantly share code, notes, and snippets.

@v11ncent
Last active February 9, 2022 19:21
Show Gist options
  • Save v11ncent/034892152991f7f8f16299f9842c7243 to your computer and use it in GitHub Desktop.
Save v11ncent/034892152991f7f8f16299f9842c7243 to your computer and use it in GitHub Desktop.
Basic GitHub Workflow

Basic Git & GitHub Workflow

Forking the repository to your GitHub account

Grab a repository and add it to your GitHub account For these examples, we're going to use the "test-repo" in the organization (https://github.com/hungry-franklin-257fd8/test-repo).

  1. Go to the repository that you want to fork.

  2. Near the top right of the screen there will be a "Fork" button. Click it and add it to your account.

Cloning the repository to your computer

Use the repository you forked in "Forking the repository to your GitHub account".

  1. Change directory in the command line to the directory you want to clone (copy) the repository into: cd Desktop.

  2. Go to the repository in GitHub and near the top right, click the green "Code" button. Select "HTTPS" and copy the command: https://github.com/hungry-franklin-257fd8/test-repo.git.

  3. Go back to your command line and paste git clone https://github.com/vince1444/test-repo.git.

  4. Now change directory into your newly cloned repository (you should still be in the directory you chose for step 1):
    cd test-repo.

Establishing a mainline & preventing push to mainline

We never want to commit to the mainline without reviewing the code.

  1. Make sure you're in the root directory of your cloned repo. Example: C:\Users\Vince\Desktop\test-repo.

  2. Add a mainline to tell git what the main branch is: git remote add mainline github_parent_repository_url, where "github_parent_repository_url" is the parent repository you forked from.
    --Example: git remote add mainline https://github.com/hungry-franklin-257fd8/test-repo.

  3. Ensure that you never push to the main branch: git remote set-url --push mainline no_push.

  4. Type in git remote -v and you should see on the second line mainline no_push (push).

Starting on work & committing changes

  1. Before starting, ensure that you have the latest changes to your local repository: git pull mainline main and
    git merge mainline main.

  2. Make your changes, add files, etc.

  3. Add all your changed files to staging: git add ..

  4. Commit your changes with a concise message: git commit -m "Concise Message".

  5. Upload your local changes to GitHub: git push origin main.

Opening a pull request

Pull requests are used to review code before committing them to the production branch.

  1. Go into your forked repository in GitHub.

  2. Near the top left, click "Pull Requests".

  3. Hit the green "New pull request" button and then the green "Create pull request" button.

  4. Give a detailed title & description and submit the pull request.

  5. When available, everyone can get together and we can review the code to make sure it works as intended without bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment