Skip to content

Brief Git Guide

Ozgurcan Oztas edited this page Feb 24, 2019 · 1 revision

Git is a distributed version control system for tracking changes in source code of software projects. It is created by Linus Torvalds in 2005 and still maintaining by Junio Hamano. Most significant advantages of git is each directory in the file system is a full-fledged, trackable repository.

A brief explanation from the official website is given below.

The Git feature that really makes it stand apart from nearly every other SCM out there is its branching model.

Git allows and encourages you to have multiple local branches that can be entirely independent of each other. The
creation, merging, and deletion of those lines of development takes seconds.

This means that you can do things like:

-Frictionless Context Switching: Create a branch to try out an idea, commit a few times, switch back to where you branched from, 
apply a patch, switch back to where you are experimenting, and merge it in.

-Role-Based Codelines: Have a branch that always contains only what goes to production, 
another that you merge work into for testing, and several smaller ones for day to day work.

-Feature Based Workflow: Create new branches for each new feature you're working on so you can seamlessly switch back 
and forth between them, then delete each branch when that feature gets merged into your main line.

-Disposable Experimentation: Create a branch to experiment in, realize it's not going to work, 
and just delete it - abandoning the work—with nobody else ever seeing it (even if you've pushed 
other branches in the meantime).

The commands below are organized to utilize git on your computer.

How to:

Installing:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git

Version check:

git --version

Globally initialize a user:

git --global global.user.name "your_name"
git --global global.user.email "your_email"

Getting-Creating Projects:

Initialize an empty repo:

git init your_repository_name

Cloning a repository:

git clone ssh://git@github.com/[your_username]/[your_repository_name].git

Snapshooting

Checking status of the repository:

git status

Add a file by giving filepath:

git add /your/file/path/1 /your/file/path/2/etc

Adding all files:

git add -A

Commit your changes to the repository:

git commit -m "[commit_your_message]"

Remove a file:

git rm -r "[file_or_folder_name]"

Share, Update:

Loading repository to the system:

git remote add origin your_github_repository_link_here

Pushing branch to the remembered repository:

git push origin [your_branch_name]

Pushing changes to the desired repository:

git push -u origin [your_branch_name]

Pushing changes to the remembered repository:

git push

Updating local repo to the newest commit:

git pull

Pulling changes from remote repository:

git pull origin [your_branch_name]

Adding a remote repository:

git remote add origin ssh://git@github.com/[your_username]/[your_repository_name].git

Branch, Merge:

Reach a certain commit:

git checkout commit_id

Branching:

git branch your_branch_name

Checking branch

git checkout your_branch_name

Deleting a branch:

git -d your_branch_name

Git system diagram

For more information, check out the official website, Github, watch this video.

Clone this wiki locally