Skip to content

tuckerzp/introduction-to-github-command-line

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction to GitHub

Get started using GitHub in less than an hour.

People use GitHub to build some of the most advanced technologies in the world. Whether you’re visualizing data or building a new game, there’s a whole community and set of tools on GitHub that can help you do it even better. GitHub Skills’ “Introduction to GitHub” course guides you through everything you need to start contributing in less than an hour.

  • Who is this for: New developers, new GitHub users, and students.
  • What you'll learn: We'll introduce repositories, branches, commits, and pull requests.
  • Prerequisites: None. This course is a great introduction for your first day on GitHub.
  • How long: This course is four steps long and takes less than one hour to complete.

How to start this course

  1. Above these instructions, right-click Use this template and open the link in a new tab. Use this template
  2. In the new tab, follow the prompts to create a new repository.
    • For owner, choose your personal account or an organization to host the repository.
    • We recommend creating a public repository—private repositories will use Actions minutes. Create a new repository
  3. After your new repository is created, wait about 20 seconds, then refresh the page. Follow the step-by-step instructions in the new repository's README.

Step 1: Create a branch

Welcome to "Introduction to GitHub"! 👋

What is GitHub?: GitHub is a collaboration platform that uses Git for versioning. GitHub is a popular place to share and contribute to open-source software.
📺 Video: What is GitHub?

What is a repository?: A repository is a project containing files and folders. A repository tracks versions of files and folders.
📺 Video: Exploring a repository

What is a branch?: A branch is a parallel version of your repository. By default, your repository has one branch named main and it is considered to be the definitive branch. You can create additional branches off of main in your repository. You can use branches to have different versions of a project at one time.

On additional branches, you can make edits without impacting the main version. Branches allow you to separate your work from the main branch. In other words, everyone's work is safe while you contribute.
📺 Video: Branches

⌨️ Activity: Your first branch

When working on a project, branches are extremely important for maintaining your own version of history. You will almost never work on release or develop directly.

  1. Open up your terminal, and clone this repository.
    gh repo clone {name of repo}
  2. Then go into your newly created directory
    cd {name of repo}
  3. Create a new branch! But first, there are a few things to learn about what to actually name it.
    • The name of your branch should be either fix/ or feature followed by a name that describes what your branch will do.
    • On EGRC specifcally, you will be using kebab case.
  4. git switch -c feature/add-readme
    • switch switches to a different branch
    • -c flag creates a new branch
  5. Move on to Step 2!

Step 2: Commit a file

You created a branch! 🎉

Creating a branch allows you to edit to your project without changing the main branch. Now that you have a branch, it’s time to create a file and make your first commit!

What is a commit?: A commit is a set of changes to the files and folders in your project. A commit exists in a branch.

⌨️ Activity: Your first commit

The following steps will guide you through the process of committing a change on Git. Committing a change requires first adding a new file to your new branch.

  1. On your new branch create a file using your favorite text editor! It can really be anything, but lets make a README.md file.
    vim README.md
  2. Make some changes to your file.
# Hello, World!
  1. Save your file and go back to the command line. If you do git status, it should say that your files are Not Staged So we need to track them! Just do git add README.md. Lets quickly define some terms that you may see when doing git status.
    • Untracked: an untracked file is a file that git is not watching for changes on.
    • Modifed: a modifed file is a file that is being tracked, but the changes are not yet staged.
    • Staged: a staged file is one that is about to be commited.
    • Commited: once a file is commited, it is added to the project's history.
  2. Time to commit your changes! Do git commit and you will be brought to a text editor.
  3. Now comes the most important part, the commit message. There is a ton of documentation on what makes a good commit message, like here, but we will quickly go over some key ideas.
    • A good commit message documents not only what has been changed but the why and how.
    • Keep the first line to say what your commit does using the imperative mood. Like add README or Handle errors in bar function. The first line should be < 50 characters long.
    • The next lines should describe why you made this commit and a bit of explanation on that change. This can be a few senteces to a few paragraphs long. Make sure to keep your lines < 72 and to use lines between paragraphs. We do not really need to put much, if anything, for this commit but it is helpful to know.
  4. Save your changes and exit the commit dialog.
  5. Push your changes to your remote branch. git push origin {your-branch-name}.
  6. Move on to Step 3! Note: Like before, you can wait about 20 seconds, then refresh this page (the one you're following instructions from) and GitHub Actions will automatically close this step and open the next one.

Step 3: Open a pull request

Nice work making that commit ✨

Now that you’ve created a commit, it’s time to share your proposed change through a pull request!

What is a pull request?: Collaboration happens on a pull request. The pull request shows the changes in your branch to other people. This pull request is going to keep the changes you just made on your branch and propose applying them to the main branch.
📺 Video: Introduction to pull requests

⌨️ Activity: Create a pull request

There are a few ways to go about creating a pull request, but we will be using GitHub CLi. Like your commit, carefully creating a title and body is an important part of creating a pr. Since this is a very small tutorial, we will keep it simple here.

  1. In your terminal, do gh pr create.
  2. You should be prompted to create a title ? Title. Write down a descriptive title and hit enter.
  3. Then you will prompted to create a body description ? Body. Write down a description of your pr. If it addresses a specific issue, make sure to mention that in your description. Something like Closes #10. Hit enter.
  4. You should get a link to your newly created pr!
  5. Move on to Step 4!
    Note: Like before, you can wait about 20 seconds, then refresh this page (the one you're following instructions from) and GitHub Actions will automatically close this step and open the next one. As a perk, you may see evidence of GitHub Actions running on the tab with the pull request opened! The image below shows a line you might see on your pull request after the Action finishes running.
    screenshot of an example of an actions line

Step 4: Merge your pull request

Nicely done friend! 😎

You successfully created a pull request. You can now merge your pull request.

What is a merge: A merge adds the changes in your pull request and branch into the main branch.
📺 Video: Understanding the GitHub flow

As noted in the previous step, you may have seen evidence of an action running which automatically progresses your instructions to the next step. You'll have to wait for it to finish before you can merge your pull request. It will be ready when the merge pull request button is green.

screenshot of green merge pull request button

⌨️ Activity: Merge the pull request

  1. Click Merge pull request.
  2. Click Confirm merge.
  3. Once your branch has been merged, you don't need it anymore. To delete this branch, click Delete branch.
    screenshot showing delete branch button
  4. Check out the Finish step to see what you can learn next!
    Note: Like before, you can wait about 20 seconds, then refresh this page (the one you're following instructions from) and GitHub Actions will automatically close this step and open the next one.

Finish

Congratulations friend, you've completed this course and joined the world of developers!

celebrate

Here's a recap of your accomplishments:

  • You learned about GitHub, repositories, branches, commits, and pull requests.
  • You created a branch, a commit, and a pull request.
  • You merged a pull request.
  • You made your first contribution! 🎉

What's next?

If you'd like to make a profile README, use the simplified instructions below or follow the instructions in the Managing your profile README article.

  1. Make a new public repository with a name that matches your GitHub username.
  2. Create a file named README.md in it's root. The "root" means not inside any folder in your repository.
  3. Edit the contents of the README.md file.
  4. If you created a new branch for your file, open and merge a pull request on your branch.
  5. Lastly, we'd love to hear what you thought of this course in our discussion board.

Check out these resources to learn more or get involved:


Get help: Post in our discussion boardReview the GitHub status page

© 2022 GitHub • Code of ConductCC-BY-4.0 License

About

Get started using GitHub in less than an hour.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published