Often when working in a project, you will be using different version control tools like SVN, GIT, Mercurial and so on. With version control, it is possible to work in a collaborative environment without losing any of the data at any of the project stage. It is essential now-a-days to have been used any of the version control for the projects undertaken.
GIT, a distributed version control system is popular and most used now-a-days. Unlike SVN, it does have a local repository refer to as staging area where the local commits are maintained. We can then push these commits to remote repository. Setting up a project using GIT is the first and foremost thing to do and it is easy as running a few commands.
You are given a remote repository url which is basically a GIT repository url that can be anything from github to bitbucket to Atlassian repository whichever vendor that we choose as remote repository. And to start with, we create a folder in our local machine with a project name and run the git bash or git command tools.
Navigate to the project folder in your git command tool:
Now, init the git repository
$ git init
This will create the .git folder which will contain all the necessary information regarding your repository. This will also create the branch in your local folder which is master by default.
Now, we will set our name and email for the git repository. This is required to track your activity when you do commits and relevant activities.
$ git config --global user.name "Ujjwal Prajapati" $ git config --global user.email "email@example.com"
Now, we add remote repository url and give it a name “origin”
$ git remote add origin https://firstname.lastname@example.org/test/test.git
Now, if you do run this command, it will show you fetch and push repository url
$ git remote -v
Now, we will be running fetch command to fetch the remote repository to our local repository
$ git fetch origin
Now, to merge it with the local copy which is basically empty now and is your master branch, we run the merge commands.
$ git merge origin/master
Now, we will have the local copy of our remote repository instance. We can now work on the files. Once we do some modification, it is essential to put our changes to remote repository which is the push action. But before doing that, we have to add our files and then commit to staging area.
$ git add "readme.txt"
Now, the file is tracked and staged. All we need to do now, is commit the file to staging area running the command.
$ git commit -m "File Added"
Now, to push it to the remote repository, all we have to do is run the push command as:
$ git push origin master
Now, you are all done setting up the project and know how to commit and track the changes. Happy working with GIT!