Git Basics in Under 10 Minutes
Git Basics in Under 10 Minutes
Donate
Stay safe, friends. Learn to code from home. Use our free 2,000 hour curriculum.
by Gowtham Venkatesan
Yes, the title is a clickbait. There is no way you can understand the
basics of git technology in just 10 minutes. But you can get pretty
close in about 25 minutes. And that is the purpose of this article.
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 1/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
If you want to get started on learning about Git technology, you’ve Donate
come to the right place. This is a comprehensive beginner’s guide to
Git. There are many clients for Git. The technology is all the same no
matter the client. But in this guide we’ll be using GitHub to understand
Git.
So What is Git?
Git is a version-control system for tracking changes in computer files
and coordinating work on those files among multiple people. Git is a
Distributed Version Control System. So Git does not necessarily rely on a
central server to store all the versions of a project’s files. Instead,
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 2/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 3/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
“Master” repository. So by using Git you can ensure you both are Donate
working on the most recent version of the repository. So you don’t
have to worry about mailing your files to each other and working with
a ridiculous number of copies of the original file. And collaborating
long distance becomes as easy as HTML ?.
Git Workflow:
Before we start working with Git commands, it is necessary that you
understand what it represents.
What is a Repository ?
A repository a.k.a. repo is nothing but a collection of source code.
Donate
git commit is a command used to add all files that are staged
to the local repository.
git merge is a command used to get the files from the local
repository into the working directory.
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 5/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
Now that we know what Git is and it’s basic terminologies, let’s see
how we can place a file under git. We’re going to do it the right way
and the difficult way. Without any GUI applications.
I’m assuming you already have a file the you want to place under
version control. If not create a sample folder named ‘MuskCult’ and
place some sample code files in it.
$ git --version
This will prompt open an installer if you don’t already have git. So set it
up using the installer. If you have git already, it’ll just show you which
version of git you have installed.
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 6/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
$ get a mac
$ git config --global --list # To check the info you just provided
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 7/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
If you did setup SSH, every git command that has a link you replace it
by:
Instead of : https://github.com/username/reponame
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 8/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
$ cd Desktop/MuskCult
Initialize Git:
And to place it under git, enter:
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 9/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
$ git add . # Adds all the files in the local repository and stage
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 10/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
$ git commit -m "First commit"# The message in the " " is given so
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 11/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
$ git reset HEAD~1# Remove the most recent commit# Commit again!
Now each time you make changes in your files and save it, it won’t be Donate
automatically updated on GitHub. All the changes we made in the file
are updated in the local repository. Now to update the changes to the
master:
The git remote command lets you create, view, and delete
connections to other repositories.
$ git remote -v# List the remote connections you have to other repo
The git remote -v command lists the URLs of the remote connections
you have to other repositories.
Now the git push command pushes the changes in your local
repository up to the remote repository you specified as the origin.
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 13/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
And that’s it. You’ve just added the files to the repository you just
created on GitHub.
to
Nowthe Git
you can Repo:
choose to revert back to the last committed version by Donate
entering:
$ git checkout .
$ git log
Each time you make changes that you want to be reflected on GitHub,
the following are the most common flow of commands:
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 15/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
$ git add .$ git status # Lists all new or modified files to be com
Now if we go and see our repo, we can identify whether the commit
was successful by looking at the commit message for each file.
Feel free to go ahead and clone the repo I created above using:
https://github.com/Gothamv/MuskCult
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 16/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Now you can work on the files you want and commit to changes
locally. If you want to push changes to that repository you either have
to be added as a collaborator for the repository or you have create
something known as pull request. Go and check out how to do one
here and give me a pull request with your code file.
Collaborating:
So imagine you and your friend are collaborating on a project. You
both are working on the same project files. Each time you make some
changes and push it into the master repo, your friend has to pull the
changes that you pushed into the git repo. Meaning to make sure
you’re working on the latest version of the git repo each time you start
working, a git pull command is the way to go.
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 17/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
Here’s two more useful git commands:
When you use git pull , Git tries to automatically do your work for
you. It is context sensitive, so Git will merge any pulled commits into
the branch you are currently working in. git pull automatically
merges the commits without letting you review them first.
When you git fetch , Git gathers any commits from the target
branch that do not exist in your current branch and stores them in
your local repository. However, it does not merge them with your
current branch. This is particularly useful if you need to keep your
repository up to date, but are working on something that might break
if you update your files. To integrate the commits into your master
branch, you use git merge .
.gitignore
So what is it?
.gitignore tells git which files (or patterns) it should ignore. It's
usually used to avoid committing transient files from your working
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 18/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
$ touch .gitignore
And you can add the following patterns to tell git to ignore such files.
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 20/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
Donate
freeCodeCamp is a donor-supported tax-exempt 501(c)(3) nonprofit organization (United States
Federal Tax Identification Number: 82-0779546)
Our mission: to help people learn to code for free. We accomplish this by creating thousands of
videos, articles, and interactive coding lessons - all freely available to the public. We also have
Donations to freeCodeCamp go toward our education initiatives, and help pay for servers,
services, and staff.
Trending Guides
Our Nonprofit
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 21/22
6/12/2020 Learn the Basics of Git in Under 10 Minutes
About Alumni Network Open Source Shop Support Sponsors Academic Honesty
Donate
Code of Conduct Privacy Policy Terms of Service Copyright Policy
https://www.freecodecamp.org/news/learn-the-basics-of-git-in-under-10-minutes-da548267cc91/ 22/22