0% found this document useful (0 votes)
75 views

An Intro To Git - Github

Git is version control software that allows users to track changes to files over time. GitHub is a company that provides hosting for Git repositories and additional collaboration features. To use Git, a user first initializes a repository locally by running "git init" in a project folder. Then files can be added, committed, and changes tracked across different versions. Additional features like branching allow users to work independently on different parts of a project before merging them together.

Uploaded by

Unknown User
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

An Intro To Git - Github

Git is version control software that allows users to track changes to files over time. GitHub is a company that provides hosting for Git repositories and additional collaboration features. To use Git, a user first initializes a repository locally by running "git init" in a project folder. Then files can be added, committed, and changes tracked across different versions. Additional features like branching allow users to work independently on different parts of a project before merging them together.

Uploaded by

Unknown User
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

An Intro to

GIT/GITHUB
An Intro to Git and GitHub
A quick aside: Git and GitHub are not the same things. Git is an open-source version control
tool created in 2005 by developers working on the Linux operating system; GitHub is a
company founded in 2008 that makes tools that integrate with Git. You do not need GitHub
to use Git, but you cannot use GitHub without using Git. There are many other alternatives to
GitHub, such as GitLab, BitBucket, and “host-your-own” solutions such as gogs and Gittea.
All of these are referred to in Git-speak as “remotes,” and all are optional. You do not need to
use a remote to use Git, but it will make sharing your code with others easier.

What is Git?
Git is software that allows you to control versions of your scripts and files in detail. It also
makes it easier to work together on projects and conduct new ideas independently. This
makes Git technology potentially beneficial for research projects. You can install the Git
software locally (on your computer). To work together, you will primarily use an online Git
platform, such as GitHub.

What is GitHub?
Based on Git’s version control technology, GitHub makes working together easier. It offers a
straightforward way to share your projects online with colleagues and the outside world.
GitHub is useful for researchers, as it allows you to find, develop and publish analysis scripts
and research software. Other developers and researchers can then use and adapt these in
turn. You can create a free GitHub account at https://Github.com/join. This is the first step
towards gaining access to Utrecht University’s GitHub environment.

Installing Git
If you are using Linux
You probably have Git installed already — try typing
Git --version
at the command line and see if it returns a version number. If it says the command
is not found, use your package manager to install it.

If you are using a RedHat style


distribution (RedHat, CentOS, or Fedora), type
sudo yum -y install Git
or on the newer distributions
sudo dnf -y install Git

If you are using a Debian-based distribution such as Ubuntu, then type


sudo apt-get Git

If you are using a Mac


Go to Git-scm.com/download/mac and download and install the Git package. The
the download should start automatically.

If you are using Windows


Go to Gitforwindows.org and download and install the Git-bash package. You have
probably already done this for the command line tutorial

Getting started on GitHub


The first thing you need to do is create a GitHub account. Since you are a
student, you can create a student account. GitHub is free to use, provided
you are happy to make all your repositories public. If you want private repositories,
you have to pay unless you are a student or an academic, in which case you can have
free private accounts.

Getting Started

Creating a local Git repository


When creating a new project on your local machine using Git, you'll first create a new
repository (or often, 'repo,' for short). To use Git, we'll be using the terminal. If you don't have
much experience with the terminal and basic commands.

To begin, open up a terminal and move to where you want to place the project on your local
machine using the cd (change directory) command. For example, if you have a 'projects'
folder on your desktop, you'd do something like:

To initialize a Git repository in the root of the folder, run the Git init command:
Adding a new file to the repo
Go ahead and add a new file to the project, using any text editor you like or running a touch
command. `touch newfile.txt` just creates and saves a blank file named newfile.txt.

Once you've added or modified files in a folder containing a Git repo, Git will notice that the
file exists inside the repo. But Git won't track the file unless you explicitly tell it to. Git only
saves/manages changes to files that it tracks, so we’ll need to send a command to confirm
that we want Git to track our new file.

After creating the new file, you can use the Git status command to see which files Git knows
to exist.

What this basically says is, "Hey, we noticed you created a new file called mnelson.txt, but
unless you use the 'Git add' command, we aren't going to do anything with it."

Adding a file to the staging environment.


Add a file to the staging environment using the Git add command.

If you rerun the Git status command, you'll see that Git has added the file to the staging
environment (notice the "Changes to be committed" line).
To reiterate, the file has not yet been added to a commit, but it's about to be.

It's time to create your first commit!

Run the command

Git commit -m "Your message about the commit"

The message at the end of the commit should be something related to what the commit
contains - maybe it's a new feature, maybe it's a bug fix, maybe it's just fixing a typo.

Creating a new branch


Now that you've made a new commit, let's try something a little more advanced.

Say you want to make a new feature but are worried about making changes to the main
project while developing the feature. This is where Git branches come in.

Branches allow you to move back and forth between the 'states' of a project. Official Git docs
describe branches this way: ‘A branch in Git is simply a lightweight movable pointer to one of
these commits.’ For instance, if you want to add a new page to your website, you can create
a new branch just for that page without affecting the central part of the project. Once you're
done with the page, you can merge your changes from your branch into the primary branch.
When you create a new branch, Git keeps track of which commit your branch 'branched' off
of, so it knows the history behind all the files.

Let's say you are on the primary branch and want to create a new branch to develop your
web page.
Here's what you'll do: Run git checkout -b <my branch name>. This command will
automatically create a new branch and then 'check you out' on it, meaning Git will move you
to that branch, off the primary branch.

After running the above command, you can use the git branch command to confirm that your
branch was created:

The branch name with the asterisk indicates which branch you're on at that time.

Creating a new repository on GitHub


If you only want to keep track of your code locally, you don't need to use GitHub. But if you
want to work with a team, you can use GitHub to modify the project's code collaboratively.

Log in and go to the GitHub home page to create a new repo on GitHub. You can find the
“New repository” option under the “+” sign next to your profile picture in the top right corner
of the navbar:
If you're looking to get into Web Development,
then AlmaBetter is the best place to start your
journey.

Join our Full Stack Web Development Program


and launch your career in tech today!

Click Here: https://link.almabetter.com/9w63

You might also like