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

INFO2180

Version Control with Git

Uploaded by

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

INFO2180

Version Control with Git

Uploaded by

Sub Quantum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

INFO2180

COMMAND LINE/
TERMINAL BASICS
GIT

WHAT IS THE COMMAND LINE/TERMINAL

▸ The command line is a text interface for your computer. It’s


a program that takes in commands, which it passes on to
the computer’s operating system to run.

▸ If you are on Windows, I suggest you try to use "Windows


Powershell." If you are using Linux or macOS then I suggest
you start by using the default "Terminal" application.

When you rst open the Terminal you will typically


see something like:

C:\Users\{username}> on Windows

or

yourusername@yourcomputername:~$ on
macOS/Linux.

For the purposes of this course we will shorten this


and simply use $ before any of the commands we
want to execute at the command line.

Note: You don't need to add the $ to the command.







fi



GIT

PWD COMMAND

▸ The rst command we want to try is the pwd command. This


stands for Print Working Directory.

$ pwd

You may see something like /home/{username}/ or C:


\Users\{username}>


fi


GIT

LS COMMAND
▸ Next let us try entering the ls command (on Windows you
can also try the dir command). This command will List the
contents of the current directory.

$ ls

So you may see something like:

Desktop/ Documents/ Downloads/


Music/ Pictures/ Videos/







GIT

CD COMMAND
▸ The third command we want to try is the cd command. This
command stands for Change Directory. So at the command line type:

$ cd

and if you know the name of the directory or path you want to go to
you can type:

$ cd {childFolderName}

e.g. $ cd Documents/









GIT

CD COMMAND

▸ You can also navigate up one directory from the one you are
currently in by using "../". For example:

$ cd ../



GIT

MKDIR COMMAND

▸ To “Make” a directory in the le system at the speci ed le


path, you can use the mkdir command. e.g.

$ mkdir some-folder

fi

fi
fi
GIT

RM COMMAND

▸ To delete (“remove”) a le at a speci ed le path we can


use the rm command. e.g.

$ rm index.html

fi

fi
fi
GIT

RMDIR COMMAND

▸ To delete a directory at the speci ed path we can use the


rmdir command. e.g.

$ rmdir some-folder/

▸ On Linux and MacOS you can also use:

$ rm -r some-folder/




fi

GIT

CP COMMAND

▸ To copy les or directories, we can use the cp command.

$ cp styles.css some-folder/

Here, we copy the le styles.css le and place it in the


some-folder/ directory.


fi
fi

fi


GIT

MV COMMAND

▸ To move a le into a directory, use mv with the source le as


the rst argument and the destination directory as the
second argument. e.g.

$ mv somefile.txt my-folder/

fi
fi

fi
There are many more commands, but those are
some of the most common and basic commands
everyone should know.
WHAT IS VERSION
CONTROL?
When you work on a project, how do you keep track
of different versions or changes in your les?

fi
some le.html
some le_v2.html
some le_not_working.html
some le_v10_ nal.html
some le_ nal_ nal.html
some le_ nally_got_it_working.html
styles.css
styles_test_something.css
fi
fi
fi
fi
fi
fi
fi
fi


fi
fi





Oh and what if someone accidentally
deletes the wrong version of a le? Or
all the les...
fi
fi
GIT

WHAT IS VERSION CONTROL?


▸ Version control systems are a category of software tools that help a
software team manage changes to source code over time.

▸ Version control software keeps track of every modi cation to the


code in a special kind of database.

▸ If a mistake is made, developers can turn back the clock and


compare earlier versions of the code to help x the mistake while
minimizing disruption to all team members.

▸ Version control protects source code from both catastrophe and


the casual degradation of human error and unintended
consequences.

fi
fi

While it is possible to develop software without


using any version control, doing so subjects the
project to a huge risk that no professional team
would be advised to accept. So the question is not
whether to use version control but which version
control system to use.

Source: https://www.atlassian.com/git/tutorials/what-is-version-control
GIT

DIFFERENT VERSION CONTROL SYSTEMS

▸ CVS - Concurrent Versions System

▸ SVN - Subversion

▸ GIT - The most popular VCS currently being used.

▸ Mercurial

▸ etc...

GIT

WHAT IS GIT?
▸ Git is a free and open source version control system

▸ It is used for tracking changes in computer les and coordinating work


on those les among a group of people.

▸ It is usually used for source code management in software development


projects, but it can be used to keep track of changes in any set of les.

▸ Git is an example of a distributed version control system (DVCS)

▸ It therefore allows full access to every le, branch, and iteration of a


project, and allows every user access to a full and self-contained history
of all changes.
fi
fi

fi

fi

GIT

WHAT IS GIT?

▸ It provides a command line interface to interact with your


les.

▸ It is installed on your local system.


fi

Now let us take a look at some of the basics of Git.


WHAT IS A
REPOSITORY?
A repository, or Git project, encompasses the entire
collection of les and folders associated with a project, along
with each le’s revision history.

Source: https://guides.github.com/introduction/git-handbook/
fi
fi
INITIALIZING A
GIT REPOSITORY
To start a new local git repository

$ git init

* Note: You should navigate to the folder that contains your code before running this.
ADD
To create a Snapshot of your les in preparation for versioning
and tells Git that you want to include updates to a particular
le in the next commit.

$ git add [filename]


$ git add about.html
fi
fi
STATUS
Displays the state of the working directory and the staging
area. It lets you see which changes have been staged, which
haven’t, and which les aren’t being tracked by Git.

$ git status
fi
COMMIT
This command records the changes in the repository along
with a message.

$ git commit -m "[descriptive message]"

$ git commit -m "Change heading on about page"


REVIEW
HISTORY
To list the version history of the current branch

$ git log
To show metadata and content changes of the les in the
speci ed commit.

$ git show [commit_hash]

$ git show f1d99a...


fi
fi
BRANCHES
GIT

BRANCHES

▸ Use a branch to isolate development work without affecting


other branches in the repository. Each repository has one
default branch (usually called main/master), and can have
multiple other branches.

▸ You can use branches to:

▸ Develop features

▸ Fix bugs

▸ Safely experiment with new ideas


Source: https://www.atlassian.com/git/tutorials/using-branches
To list all existing branches

$ git branch
To create a new branch

$ git branch [branch-name]

$ git branch feature-1


To switch to a branch

$ git checkout [branch-name]

$ git checkout some-other-branch


You can also create and switch to a branch in one command

$ git checkout -b [branch-name]


To delete a branch

$ git branch -d [branch-name]


MERGE
GIT

MERGE

▸ Merging is the way in which Git takes the forked history of


your source code and puts it back together again. It allows
you to take the independent lines of development
(branches) and integrate them into a single branch.
Source: https://www.atlassian.com/git/tutorials/using-branches/git-merge
Source: https://www.atlassian.com/git/tutorials/using-branches/git-merge
To merge one branch into another

$ git merge [branch]


So far all of the commands we have learnt, operate on les
located on our local computer. However, there comes a
time when you will need to share and collaborate on this
code with others.

fi
GITHUB
http://www.github.com
GIT

WHAT IS GITHUB?
▸ Github is a website and cloud based service.

▸ It is used to keep a copy of your local repository on a remote


server.

▸ It helps developers to manage, share and collaborate with


others on their code.

▸ You can view your code online, view the commit history and see
the changes between versions of the les, view branches, etc.

▸ And of course...it uses Git.


fi

CLONING
To download a project from Github along with its entire version
history

$ git clone [url]

$ git clone https://github.com/uwi-info2180/


info2180-ajax.git
REMOTE
This command lets you create, view, and delete connections to
other repositories.

$ git remote add <name> <url>
$ git remote
$ git remote rm <name>

$ git remote add origin https://github.com/john.git
PUSH
Uploads all local branch commits to GitHub

$ git push [alias] [branch]

$ git push origin master


FETCH
Downloads all history from the repository bookmark

$ git fetch [bookmark]

Note: The bookmark here could refer to a branch or a speci c commit hash.
fi
PULL
Downloads most recent changes from remote repository and
incorporates (or merges) those changes.

$ git pull
There are many other Git commands but these are a few of
the basics.
GIT

RESOURCES
▸ Installing Git - https://git-scm.com/book/en/v2/Getting-
Started-Installing-Git

▸ Try Git - https://try.github.io/

▸ Learn Git - https://www.codecademy.com/learn/learn-git

▸ Github Pages - https://pages.github.com/

▸ A Guide to Using Github Pages - https://www.thinkful.com/


learn/a-guide-to-using-github-pages/

▸ Github Desktop GUI - https://desktop.github.com/

You might also like