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

All About Git and Github

Git is an open-source version control system that records changes to files over time, allowing previous versions to be recalled later. It allows branching, or creating different versions of files separate from the main branch. GitHub is a popular cloud-based hosting service for Git repositories that allows for collaboration and version control. To set up Git, different commands are used depending on your operating system - Linux, Mac, or Windows. Basic Git commands include commands for navigating directories, initializing repositories, committing changes, pushing to remote repositories, and more.

Uploaded by

Samir Shrestha
Copyright
© Public Domain
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

All About Git and Github

Git is an open-source version control system that records changes to files over time, allowing previous versions to be recalled later. It allows branching, or creating different versions of files separate from the main branch. GitHub is a popular cloud-based hosting service for Git repositories that allows for collaboration and version control. To set up Git, different commands are used depending on your operating system - Linux, Mac, or Windows. Basic Git commands include commands for navigating directories, initializing repositories, committing changes, pushing to remote repositories, and more.

Uploaded by

Samir Shrestha
Copyright
© Public Domain
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

What Is Git?

Git is what is known as an open-source version control system which means that it records files
over a period of time and these changes can be recalled at a later date. You can do a lot with Git
whether it can be branching (creating something that is different from the master branch (the one
you would most likely be working on)) or just committing to a repository (programming jargon
simply calls it a repo).

What Is Git Article - A more in-depth article concerning Git (Do not be alarmed at the fact it
uses BitBucket)

What Is GitHub?

While there are multiple different cloud-based version control systems on the web, GitHub
remains to be one of the most popular and it is free too! It can be found here: GitHub

Basic Setup

Depending on what OS (operating system) you have the setup might be slightly different.

Linux (Will specifically be on a Debian system ie Ubuntu)

Go to your terminal and type these commands (keep in mind these will be using the root
preference)

sudo apt update This will essentially update your system.

sudo apt install git This will install Git on the system.

git --version This is used to verify its downloaded.

Mac

Will also be in the terminal

ruby -e "$(curl -fsSL


https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew doctor Will installs an application known as Homebrew which helps simplifies the
installation of software on Mac systems.

brew install git Will install Git on your system


Windows

Navigate to Git-SCM: Git SCM Download

Git SCM will download protocol but also a BASH, a command line

(Sidenote: I would personally recommend learning the command line as it is a lot more powerful
and if you understand the command line you would also understand the GUI. One GUI based
version control systems is GitKraken)

Basic/ Most Used Bash Commands (Keep in mind there are several modifiers for each
command)

ls - lists the folders and files in the working directory (the current directory you are in)

cd - changes directory

pwd- used to find the path for the current directory

mkdir- make a directory

touch - update the access and or modification date of a file or directory without opening, saving
or closing the file.

cat - print files to stdout

mv - moves files and folders

cp - copies files or folders

rm - remove files and folder (look into modifiers for this one)

chmod- Change mode so you can set permissions for read, write and execute for the user,
members of your group and others. (Binary can be used for this)

man - can be used to look up any commands ie man cd

Using GitBash/Terminal to Access GitHub

1. Configure Git via git config --global user.name "[name]" and git config
--global user.email "[email address]"
2. Navigate to your working directory (Keep in mind you cannot just cd to the directory,
you have to work your way to it, so I personally keep a folder called Programming in my
home directory)

3. Initialize a Git Repo via git init

Now, this is where you can branch-of, you have two options, pushing a new repo or pushing a
preexistent repo.

Pushing a New Repo

1. Commit your repo via git commit -m "first commit"

2. Remote add your repo via git remote add origin <url>

3. Push to your repo via git push -u origin master

For Pushing an Existing Repo

1. Remote add your repo via git remote add origin <url>

2. Push to your repo via git push -u origin master

Now that you have your repo set up, these are some helpful commands:

git status Used to check what has changed ie additions and deletions

git add <file> Used to add files to commit if used with a period (.) it adds all of the files

git commit -m "message" Use to commit changed, but it is on the local system, the -m can be
changed to things such as -u which is an update but it is recommended to keep with an -m

git push Used to push changes to GitHub

git reset Can be used after commit to reset the commits (Good if you accidentally add a file
you did not want)

git pull <url> Can be used to pull from any git repo, leave the URL out if your updating your
current repo

.gitignore

The .gitignore file is useful for stopping certain files from committing automatically. It should
automatically be in a repo when you create a project. To use it just cd to the directory where the
file you want to exclude is and use pwd to find the directory pathing. Then copy the path into the
file, it should look like a text file, and then add the name of the file you want to exclude.

Example: User/Jun/Programming/src/something.java

Branching in Git (For advanced user)

Branching is useful when many people are working on the same project or when you have
multiple versions of the same project. The major advantage of branching is when you want to
add a feature without compromising the integrity of the master branch.

Branching Commands

git branch [branch-name] Used to create a new branch

git checkout [branch-name] Used to switch branches

git merge [branch] Used to merge branch commits (usually people use this with a branch and
the master)

git branch -d [branch-name] Used to delete a branch

For more information consult the Git Documentation here. Feel free to message me.

You might also like