An Intro To Git - Github
An Intro To Git - Github
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.
Getting Started
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."
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.
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.
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.
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.