git - in simple way

git - in simple way

Git is a fantastic thing. Its a version control system, so it lets you see previous changes, collaborate with others, see what they changed. Its great way to share the Code with developers or your team.

1. Setup
  1.  Download git for OSX 
  2. Download git for Windows
  3. Download git for Linux

Once git is installed, you’ll need to set up a couple of things. Fire up your terminal and type in the following:

git config --global user.name "Your Name"
git config --global user.email your@email

These settings will identify you for all of your git repositories.

2 .create a new repository

create a new directory, open the directory and perform a git init to create a new git repository.

3. checkout a repository

Create a working copy of a local repository by running the command

git clone /path/to/repository

when using a remote server, your command will be

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

4. workflow

your local repository consists of three "trees" maintained by git.

  1. the first one is your which holds the actual files.
  2. the second one is the which acts as a staging area and
  3. finally the  which points to the last commit you've made.
5. add & commit

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 
git commit -m "Commit message"
Now the file is committed to the HEAD, but not in your remote repository yet.

6. pushing changes

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

7. branching

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>

8. update & merge

to update your local repository to the newest commit, execute
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>

replace local changes

in case you did something wrong, which for sure never happens ;), you can replace local changes using the command
git checkout -- <filename>
this replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept.

If you instead want to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it like this
git fetch origin
git reset --hard origin/master

-----------------------------------------------

Thanks --

Shrikant M.

To view or add a comment, sign in

More articles by Shrikant More

  • Handling "exhausting available ports" in Jmeter

    JMeter is a wonderful tool to stress test your website and your application architecture. In environments with a very…

    13 Comments
  • Handling Exception in Webdriver

    Whenever we are working with web driver, we come across different exceptions depending upon the scenarios, same code…

    2 Comments
  • Why do we Test?

    The people who test in order to ensure the product is released with good enough quality. Or those who test to “to be…

  • Bench-marking for Performance Testing

    If you are planning performance testing of APIs then bench-marking is very important task we just cant ignore ! If your…

  • API Testing

    An API (Application Programming Interface) is a collection of software functions and procedures known as API calls…

    1 Comment
  • Performance Testing using Jmeter

    Performance testing is crucial to determine that the web application under test will satisfy high load requirements…

    5 Comments

Others also viewed

Explore content categories