Getting started with GIT

I. Why Git?

git config
Configure the author name and email address to be used with your commits.

Note that Git strips some characters (for example trailing periods) from user.name.
git config --global user.name "Sam Smith"

git config --global user.email sam@example.com
git init
Create a new local repository

git clone
- Create a working copy of a local repository:

git clone /path/to/repository


- For a remote server, use:

git clone username@host:/path/to/repository

git add
Add one or more files to staging (index):

git add <filename>

git add *

git commit
Commit changes to head (but not yet to the remote repository):
git commit -m "Commit message"
Commit any files you've added with git add, and also commit any files you've changed since then:

git commit -a

git push
Send changes to the master branch of your remote repository:

git push origin master


git status
List the files you've changed and those you still need to add or commit:

git remote
If you haven't connected your local repository to a remote server, add the server to be able to push to it:
git remote add origin <server>
List all currently configured remote repositories:
git remote -v

git branch
List all the branches in your repo, and also tell you what branch you're currently in:

git branch

Delete the feature branch:

git branch -d <branchname>


git checkout
Create a new branch and switch to it:

git checkout -b <branchname>

Switch from one branch to another:

git checkout <branchname>



git merge
Join two or more development histories together
git merge <branchname>

git stash
Save the changes if you don't want to commit immediately
git stash
and then when you want to apply the stash
git stash pop

git reset
You know when you commit changes that are not complete, this sets your index to the latest commit that you want to work on with.
git reset <:mode:> <:COMMIT:>
git remote
To check what remote/source you have or add a new remote
git remote to check and list. And git remote add <:remote_url:>

git fetch
when you do a git fetch, it gets all the changes from the remote repository, stores the changes in a separate branch in your local repository and if you want to reflect those changes in your corresponding branches, use a git merge to do that.

git pull
when you do a git pull, it gets all the changes from the remote or central repository and attaches it to your corresponding branch in your local repository.
→ git pull = git fetch + git merge
git log
show all commits in the current branch's history
.gitignore file:

Git sees every file in your working copy as one of three things:
tracked - a file which has been previously staged or committed;
untracked - a file which has not been staged or committed; or
ignored - a file which Git has been explicitly told to ignore.

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store