Sunday, 11 February 2018

How to upload your project to Bitbucket or GitHub using Git

Today we are going to see how to upload our projects or files to our Bitbucket or GitHub repository through command line using Git.If you have not downloaded Git yet then download it from here with one click - Download Git. To upload our any project or files which are on our local machine, we will use some git commands to push it to Bitbucket or GitHub.If you are not aware of it then I will suggest you to read this article before you actually start uploading your project or files to Bitbucket or GitHub so that you will have some idea about git commands.Check it out that article here - What is Git ? List of Basic commands and their use.

How to upload your project to Bitbucket or GitHub using Git

We are diving this process of uploading project or files to Bitbucket or GitHub into two cases:
Case 1) If single user is working on a project
Case 2) If multiple users are working on a project

Case 1) If single user is working on a project
  • Create one repository on Bitbucket or GitHub.If you do not have an account then create one here. For Bitbucket User - Create Bitbucket Account for Free. For GitHub User - Create GitHub Account for Free
  • Copy the created repository link and go to the path in cmd where you want to keep this project(WAMP/XAMPP/MAMP/LAMP) and in cmd write "git clone url". Here you have to paste copied url in place of url and hit enter.If you are asked to enter username and password then you can enter it.
  • Go inside that folder which s just created by cloning and create your project there or you can create any html file as we are just learning it
  • In cmd, execute command "git add ." so it will add all your new created files
  • Then execute command "git commit -m 'message'", here 'message' will anything you want to write about your changes so that if you visit this folder on Bitbucket or GitHub, you will have idea about what changes you made in that commit
  • Then execute command "git push" and all your code will be on Bitbucket or GitHub repository

Case 2) If multiple users are working on a project
All the process is same as Case 1 process.You can add multiple users from settings.Every users will take clone from the repository and will set to their local machine as mentioned in above steps.

Now different users create different files on their local machine and pushes to remote repository but the user who pushes first will able to successfully add the file which he/she created.

Now when second user pushes his/her created file to repository then in command line he/she will get message that the content on the remote repository is different from the content you have on your local machine so take pull first.So second user will execute command "git pull" so the file which is pushed by first user will be on second user's local machine.Then again second user need to perform last 3 steps in case 1.

This was the thing when first user creates x.html file and second user creates y.html file but what if they both work on same file ???

If both users working on same file then first user will be able to push successfully but when second user pushes, he/she need to take pull first as discussed above and here there are two possibilities that code might merge or code get conflict.

If second user get merge then there is no issue, second user can follow last 3 steps in case 1 again and this is how second user will push code/file to remote repository but if second user gets conflict means if second user changes some code which is already different in remote repository then it will show conflict in your local repository and it will say like remote repository contains this code and your repository contains this code , in this case you can edit that code by keeping both code or removing your code or by removing remote repository's code.But second need not to remove all code , keep it in mind.Second user will remove only that much code which making conflict.

Take a look at below conflict code. "HEAD" section will contain your code and after "====" this kind of line it will be remote repository'code.It means the code which first user pushed to remote repository. 

<<<<<<<<<<<< HEAD
var x = x + y;
==================
var x = x*y;
>>>>>>>>>>>>>>>>>>>>>

So, if you code is correct then do as mention below,

Keep : var x = x + y;

Remove: <<<<<<<<<< HEAD
              ==============
              var x = x*y;
              >>>>>>>>>>>>>>>>

If, remote repository's code is correct then, do as mentioned below,

Keep : var x = x*y;

Remove: <<<<<<<<<< HEAD
              ==============
              var x = x+y;
              >>>>>>>>>>>>>>>>

If both lines are not needed then you can remove all these lines.

Upload your project to Bitbucket or GitHub using Git

Latest
Next Post

post written by: Dhaval Thakkar

Dhaval Thakkar is an enthusiastic web developer who is passionate about learning new things and always ready to help other developers.Just Web Code is a way to provide web solutions to web developers.

0 comments: