counter easy hit
How to Automate Retail- Tools and Strategies
Retail Automation: Tools and Strategies
July 20, 2020
How to find ideas for first projects
How to find ideas for first projects
July 21, 2020

Git and GitHub for beginners

Git and GitHub for beginners

Git and GitHub for beginners

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). This is a brief summary of Git and GitHub for beginners.

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




You might also like: The misconceptions about a programmer’s life

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 – This will install an application known as Homebrew which helps simplifies the installation of software on Mac systems.

brew install git – It 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 are GitKraken). This will help a lot to understand Git and GitHub for beginners.




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




You might also like: What it was like learning programming in the early 1970s

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




You might also like: The best way to learn how to code

.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] – This is used to create a new branch

git checkout [branch-name] – Used to switch branches

git merge [branch] – This is 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.  We hope that this guide for Git and GitHub for beginners helps someone out there.

Happy coding!