How Do I Access Build Instructions in Dimensions Again

Introduction

In this lesson, we'll cover common Git commands used to manage your projects and to upload your piece of work onto GitHub. Nosotros refer to these commands as the basic Git workflow. When you're using Git, these are the commands that you'll use seventy-80% of the time. So if you can become these down, yous'll be more than halfway washed mastering Git!

Learning Outcomes

Past the terminate of this lesson, y'all should be able to do the following:

  • How to create a repository on GitHub
  • How to get files to and from GitHub
  • How to have "snapshots" of your code

Assignment

Before you start!

  • Github recently updated the way it names the default branch. This means you lot demand to make sure you are using a recent version of git (ii.28 or later). You can check your version by running: git --version
  • If yous haven't already, fix your local default git branch to main. You tin do so by running: git config --global init.defaultBranch main
  • For more data on the modify from main to main see GitHub'due south Renaming Repository.

Create the Repository

  1. You should have already created a GitHub account in the Setting Up Git lesson. If yous haven't done that yet, you tin sign up here.

  2. Create a new repository past clicking the button shown in the screenshot below.

  3. Give your repository the proper name "git_test" in the repository name input field. Bank check "Add a README file". And and so create the repository by clicking the green "Create repository" push at the bottom of the page.

  4. This will redirect you to your new repository on GitHub. To get set to copy (clone) this repository onto your local machine, click the green "Lawmaking" push. And so select the SSH option, and re-create the line below information technology. Notation: Yous MUST click the SSH pick to become the correct URL.

  5. Allow's apply the command line on your local machine to create a new directory for all of your Odin projects. Create a directory called repos with the mkdir command in your abode folder. If you're not sure if you lot're in your home folder, just blazon cd ~. One time information technology's fabricated, movement into it with the cd command.

  6. At present it'southward time to clone your repository from GitHub onto your computer with git clone followed by the URL you lot copied in the last step. The total command should look similar to git clone git@github.com:USER-Name/REPOSITORY-NAME.git. If your URL looks like https://github.com/USER-NAME/REPOSITORY-Name.git, y'all have selected the HTTPS selection, not the required SSH option.

  7. That's information technology! Yous take successfully connected the repository you created on GitHub to your local automobile. To test this, you can cd into the new git_test folder that was downloaded and and so enter git remote -v on your command line. This will brandish the URL of the repository you created on GitHub, which is the remote for your local copy. You may have also noticed the discussion origin at the start of the git remote -v output, which is the name of your remote connectedness. The proper noun "origin" is both the default and the convention for the remote repository. But it could take only equally easily been named "party-parrot" or "dancing-banana". (Don't worry about the details of origin for now; information technology volition come again near the end of this tutorial.)

Use the Git Workflow

  1. Create a new file in the git_test folder called "hello_world.txt" with the command touch hello_world.txt.

  2. Type git status in your terminal. In the output, find that your hello_world.txt file is shown in red, which ways that this file is not staged.

  3. Blazon git add hello_world.txt. This command adds your hello_world.txt file to the staging area in Git. The staging area is part of the 2-stride process for making a commit in Git. Think of the staging area as a "waiting room" for your changes until yous commit them. Now, type git status once again. In the output, observe that your file is now shown in green, which means that this file is now in the staging expanse.

  4. Blazon git commit -m "Add together hello_world.txt" and and then blazon git status once more. The output should at present say: "nothing to commit, working tree clean", indicating your changes take been committed. Don't worry if you get a message that says "upstream is gone". This is normal and only shows when your cloned repository currently has no branches. It will exist resolved once yous accept followed the remainder of the steps in this projection.

    The message, "Your branch is ahead of 'origin/main' by 1 commit" just means that y'all now have newer snapshots than what is on your remote repository. You will be uploading your snapshots further downwards in this lesson.

  5. Type git log and wait at the output. You lot should see an entry for your "Add hello_world.txt" commit. You will as well see details on the author who fabricated the commit and the date and time of when the commit was made. If your terminal is stuck in a screen with (END) at the bottom, merely press "q" to escape. You can configure settings for this later, but don't worry about it besides much for now.

Change a file or two

  1. Open README.dr. in your text editor of choice. In this case, we will open up the directory in Visual Studio Code by using the command lawmaking . inside your repository.

    MacOS users: If your concluding reads "control not establish: code", you must caput back to Control Line Basics and follow the instructions provided to permit this control to work.

  2. Add "Hello Odin!" to line three of README.md and salve the file with "Ctrl+Due south" (or "Command+Southward" on Mac).

  3. Back in your terminal (or in the fancy congenital-in terminal in Visual Studio Lawmaking with Ctrl + ` ), type git status. You lot'll notice that README.dr. is now shown as not staged or committed.

  4. Add together README.doc to the staging area with git add README.dr..
  5. Tin you guess what git status volition output at present? README.md volition be displayed in green text. That means README.md has been added to the staging expanse. The file hello_world.txt volition not show up because information technology has non been modified since it was committed.

  6. Open hello_world.txt, add some text to it, save it and stage it. Yous tin use git add . to add all files in the current directory and all subsequent directories to the staging area. Then, type git status once more, and everything should at present be in the staging area.

  7. Finally, let's commit all of the files that are in the staging area and add a descriptive commit bulletin. git commit -grand "Edit README.doctor and hello_world.txt". Then, blazon git status once once more, which volition output "nothing to commit".

  8. Take one last look at your commit history by typing git log. You should now encounter iii entries.

Push Your Work to GitHub

Finally, allow'southward upload your work to the GitHub repository you created at the start of this tutorial.

  1. Blazon git push. To be more specific, type git push origin principal. Since you are not dealing with some other branch (other than master) or a different remote (as mentioned above), yous tin leave it as git push to relieve a few keystrokes. NOTE: If at this point you receive a bulletin that says "Support for password hallmark was removed on August thirteen, 2021. Please utilise a personal admission token instead.", you lot have followed the steps incorrectly and cloned with HTTPS, not SSH. Delight follow these steps to modify your remote to SSH, then attempt to push to Github.

  2. Type git status ane final time. Information technology should output "Your co-operative is up to date with 'origin/main'. zip to commit, working tree clean".

  3. When you lot reload the repository on GitHub, you should come across the README.md and hello_world.txt files that y'all but pushed at that place from your local car.

Cheatsheet

This is a reference listing of the nearly commonly used Git commands. (You lot might consider bookmarking this handy page.) Try to familiarize yourself with the commands so that you lot can somewhen remember them all:

  • Commands related to a remote repository:
    • git clone git@github.com:USER-Proper noun/REPOSITORY-Proper name.git
    • git push or git push button origin chief (Both accomplish the aforementioned goal in this context)
  • Commands related to the workflow:
    • git add .
    • git commit -g "A message describing what you accept done to make this snapshot different"
  • Commands related to checking condition or log history
    • git status
    • git log

The basic Git syntax is program | action | destination.

For example,

  • git add together . is read as git | add | ., where the period represents everything in the current directory;
  • git commit -yard "message" is read every bit git | commit -chiliad | "message"; and
  • git status is read as git | status | (no destination).

Git Best Practices

There's a lot to learn about using Git. Simply it is worth taking the time to highlight some best practices so that you can be a ameliorate collaborator. Git is not only helpful when collaborating with others. Information technology'southward also useful when working independently. You volition be relying more than and more on your own commit history in the future when revisiting sometime code.

Two helpful all-time practices to consider are atomic commits and leveraging those atomic commits to make your commit letters more useful to future collaborators.

An atomic commit is a commit that includes changes related to simply one feature or job of your plan. There are two main reasons for doing this: first, if something you change turns out to cause some problems, it is easy to revert the specific change without losing other changes; and second, it enables you lot to write better commit messages.

Conclusion

You may not feel completely comfortable with Git at this point, which is normal. It'southward a skill that y'all will get more comfy with every bit yous utilize it.

The main thing to take away from this lesson is the basic workflow. The commands you've learned hither are the ones y'all will exist using the most ofttimes with Git.

Don't worry if you lot don't know all the commands yet or if they aren't quite sticking in your memory still. They will soon be seared into your brain as y'all use them over and over in time to come Odin projects.

In afterwards Git lessons, we will cover some of the more advanced Git features, such as branches. They will further expand your abilities and make you more productive.

For now, concentrate on using the basics of Git that you've learned here for all of your projects from now on. You will soon know each of the basic Git commands from retention!

Bonus: Irresolute the Git Commit Message Editor

Equally a bonus to this section, if you are using Visual Studio Code (and you should be if you lot're following this curriculum) and you don't want to get stuck writing a commit message in Vim because you accidentally used git commit without the message flag (-m), this command will make Visual Studio Code open a new tab with the ability to write your commit message and an optional description below it: git config --global core.editor "code --wait".

At that place volition be no confirmation or any output on the terminal after entering this command. To make a commit with Visual Studio Code every bit the text editor, make sure to use the git commit control without the -m flag. But type git commit and no message after that. Once you practice this, a new tab will open. At present you lot tin write your message, and provide more information if y'all want, correct beneath it. After typing your commit message, save it and leave the tab.

With that out of the fashion, now you can choose to use either git commit -yard <your message here> or git commit and enter your message with Visual Studio Code!

Knowledge Check

This section contains questions for you to bank check your understanding of this lesson. Review the above materials for answers if the questions beneath are difficult to answer by yourself.

  • How do you lot create a new repository on GitHub?
  • How do you copy a repository onto your local motorcar from GitHub?
  • What is the default proper noun of your remote connexion?
  • Explain what origin is in git push origin master.
  • Explain what main is in git push origin chief.
  • Explicate the two-stage system that Git uses to relieve files.
  • How do you check the status of your electric current repository?
  • How exercise you add files to the staging area in git?
  • How do you lot commit the files in the staging area and add a descriptive message?
  • How practice you push your changes to your repository on GitHub?
  • How exercise yous look at the history of your previous commits?

bondipoper1991.blogspot.com

Source: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/git-basics

0 Response to "How Do I Access Build Instructions in Dimensions Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel