Git – Simple and Basic to Get Started

Git – Simple and Basic to Get Started

System Environment Setup

Download and Install Git - BASH and GUI.

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files.

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is easy to learn and has a tiny footprint with lightning fast performance.

Download and Install

Now after downloading git from their website, you can now easily install git. I will leave it up to as it is easy to install your your preferred website. Anyways, almost all major operating system is supported. After, you install git, all commands of git is now available on console.

Basic Commands

Create / Initialized a Project Repository

Inside your project, right click or open GIT BASH in the root directory.
Type this command to initialized the current directory as a repository.
git init

 

Clone or Fetch your Remote Repository

But to be able to push later, I adviced to make your own git online.
There are lots of host to choose from, its free yet it is public repository.
The most well-known git host is github which is now maintain by Microsoft.

Create a working copy of a local repository by running the command.
git clone /path/to/repository
and when you want to use a remote server of your git repo,
git clone username@host:/path/to/repository

 

Adding and Saving every related file Changes.

You can propose changes (add it to the Index) using
git add <filename>
git add *
This is the first step in the basic git workflow. To actually commit these changes use
git commit -m "Commit message"
Now the file is committed to the HEAD, but not in your remote repository yet.

 

Submitting local changes to your remote Git repo.

Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute
git push origin master
Change master to whatever branch you want to push your changes to.

If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with
git remote add origin <server>
Now you are able to push your changes to the selected remote server

 

Dealing with Git branches specially Master.

Branches are used to develop features isolated from each other. The master branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.

create a new branch named "feature_x" and switch to it using
git checkout -b feature_x
switch back to master
git checkout master
and delete the branch again
git branch -d feature_x
a branch is not available to others unless you push the branch to your remote repository
git push origin <branch>

 

Updating or Merging some branch to Master branch.

To update your local repository from the remote branch, giving that you had added your remote git as origin.
git pull
in your working directory to fetch and merge remote changes.
to merge another branch into your active branch (e.g. master), use
git merge <branch>
in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged with
git add <filename>
before merging changes, you can also preview them by using
git diff <source_branch> <target_branch>

 

Making new Version or Release ready for public.

It's recommended to create tags for software releases. This is a known concept, which also exists in SVN. You can
create a new tag named v1.0.0 which obviously look like a version name. Yes! that's the primary plan for tags.
The 1b2e1d63ff  hash is the first 10 characters of a certain commit that you want to make as a release.
git tag v1.0.0 1b2e1d63ff

 

Showing information about Project history.

Before I start explaining something about git log command, please be aware that you must press 'q' to exit the log,
to be honest, at first I need to close the console just to get rid of the log console blocking me to type any command.

Now that you are getting familiar with the basic git command, the next most important command before we finish
this topic is in relation to logging, as the heading implies. Git log means, showing all saved changes at each point.
git log

That's not it, you can also filter or specify commits like what if you only want to see the commit of someone?
This might not be applicable to someone who start git but, you should be familiar that anyone can push commit
if you as the repo owner authorized them or someone fork your project, meaning clone for experimentation only.
git log --author=bob

You can also use this another logging command to show log in just one line only showing the commit id, message,
and branch affected by this commit.
git log --pretty=oneline

Or maybe you want to see an ASCII art tree of all the branches, decorated with the names of tags and branches:
git log --graph --oneline --decorate --all

The next git log command will not only show what the previous command can show but also all files staged and
committed to the current branch. In each commits.
git log --name-status

To know more about specific git command, you can visit the documentation but, you can also use the local built-in
docs just by typing git the command then --help, easy as that!
git log --help

 

Returning to Point when everything is Ok!

In case you did something wrong, you can replace local changes using the command this replaces the changes in
your working tree with the last content in HEAD. If you instead want to drop all your local changes and commits,
meaning, you want to return to initial point before you start making changes on the current repository which
will fetch the latest history from the server.
git fetch origin
git reset --hard origin/master

Summary

Basic GIT COMMAND LIST!

- To initialized new git.
git init

- Log all branches available.
git branch

- Create new branch.
git branch nameofbrach

- Delete existing branch.
git branch -D nameofbrach

- Switch to the said branch if exist, file will also refresh.
git checkout nameofbranch

- Check any changes and modified or even new file.
git status

- Add file to stage or ready for commit.
git add nameoffile.ext

- Commit changes to the current target branch.
git commit -am "message of the current commit"

- Add remote repository to push in.
git remote add origin http://repo.url.git

- Remove current local remote. rm == -D
git remote rm origin

- Check current repository online url.
git remote -v

- Push the target branch on the git server.
git push origin nameofbranch

- Log previous commits.
git log

- Create new branch referencing the current branch.
git checkout -b origin/nameofbranch

- Merge the current group to the current branch selected.
git merge origin/nameofbranch

- Push changes to remote git repo of the branch declared, master.
git push origin master

- Show the current local user.email to handle remote git repo. 
git config --global user.name

- Show the current local user.email to handle remote git repo.
git config --global user.email

- If you are on the branch you want to rename:
git branch -m new-name

- If you are on a different branch:
git branch -m old-name new-name

- Delete the old-name remote branch and push the new-name local branch.
git push origin :old-name new-name

- Reset the upstream branch for the new-name local branch.
- Switch to the branch and then:
git push origin -u new-name

Constantly evolving with the latest software design techniques and related technologies. Please feel free to browse my Qualifications.

Leave your Thoughts