As software developers, often we tend to work on local machine and upload a project when we’re done. This case is fine when the only developer who works on project is you and the changes are small.However when you are dealing with large project with more than one person , you will need to store source code and share it between developers in order to work on the same project.This case lead us to use version control software. The basic concept of version control is :
- Check out the project from the repository
- Make changes
- Check in/commit/submit changes to the repository
Let’s start by downloading version control software (Git) to our machine. You can download it from http://git-scm.com/ and as a Git solution i’m going to use BitBucket, you can use GitHub or other services, the explanation above applies most of them.
Since i use Windows, after installing Git in the right click appears Git Bash Here and Git GUI Here options, do right click the folder that you want to Git to use and select Git Bash Here and it’ll automatically open console from that directory.
First thing you have to do is assign the folder as local git folder in order to do so run code below
git init # assigning the folder as local repository git remote add origin https://UserName@bitbucket.org/UserName/RepositoryName.git # adding remote git URL
Now you almost done.The URL above in the code is remote URL of git repository.You can get it by simple creating repository on BitBucket.
As we don’t have any other branch except master which is default ,if you want to create new branch just run
git branch BranchName # will create branch
and to switch new branch
git checkout BranchName
checking which branch you are currently using and which files are not tracking or need to be commit
So far we create local repository and branch and added new remote one.Time to commit some codes/files, since i have an existing project i’ll push the project to server.Before pushing our code optionally we can set our user name and email to git.
as i mentioned above i have already project that i want to push if i run get status Git will show me that the folder that my project located is not tracking therefore we need to add project folder to tracking system of Git by doing
get add .
After add, . (period) indicates including whole files and folders.Now we can push our project. It will ask your password which is you set when you registered on Git repository service. In case you want to fetch a project from repository into your local use
git pull origin/master
Those are basic concept of Git,there are a lot more than this so go ahead and check documentation https://git-scm.com/doc