Basic Git commands

Check if Git has already been installed, Git is usually preinstalled on Mac and Linux.

git --version

Type the following command and then press enter: Tell Git who you are First, you need to tell Git who you are:

git config –global user.email “you@example.com”
git config –global user.name “Your Name”

Some basic Git operations
When we worked on GitHub, the basic work cycle like the fork,  edit, commit, pull request,  merge. The same cycle, with a few differences, is what we will work through on the command line.

Getting the current branch

$ git status
# On branch master
nothing to commit (working directory clean)

Merge code from remote branch called dev to local user alex

git checkout dev
git pull
git checkout alex
git merge dev

Merge code from local alex to remote branch

git checkout dev
git merge alex
git push
git checkout alex

git branch commands’ various options. -a shows all local and remote branches, while -r shows only remote branches.

Show all local and remote branch

$git branch -a

Show all remote branch

$ git branch -r
$ git branch -v -r

There’s also another way to do figure out what branches are on your remote by actually using the remotely related commands, git remote and git ls-remote. The former displays plenty of information about the remote in general and how it relates to your own repository, while the latter simply lists all references to branches and tags that it knows about.

$ git remote show origin
$ git ls-remote --heads origin

Conflict Merge error
While merging file from master to local alex branch, sometime we may cause conflict merge error. We can solve the conflicted merge error in the number of ways. If we want to merge conflict file to remote master file then we can use git command.

git checkout master hitest.php

Or

git add .
git stash

Reset last committed or undo: The 1st command will Undo local and second will force delete from remote

git reset --hard HEAD^1
git push -f

Check Last two week commits

   git log --since=2.weeks