Till now you must have explore git init, git clone, git push, git pull etc command, but working with git in a professional organization is a lot more tough as the project goes live, involves money and needs to be maintained for who knows how many decades! Working with branches, writing correct names for commits and then merging them is a scary task because you don’t want to spoil a repository! Right! And trust me I have never found a single guide on the web which has explained this in an efficient manner! Nothing!! Not even their own documentations! So, here are 5 step procedure to work with git repositories!
1.Initialize Repository and setting up remote
Now understand carefully where you have to use git init command. It is needed to be inside the folder where you project resides and check carefully that.git file is created. Now, set up the remote origin to a private repository via git remote origin https://xyz.git. origin is how you would refer your remote here!
2. Working with Branches
Create a branch on the remote. Now on the local,try understanding this that you would create a local branch based on the branch created at server so that you would push the changes onto that feature branch only. And also, name the branch based on functionality of project you are currently working on :
create a branch on the repository called authentication for instance
git fetch origin– to fetch all the new created remote branches
git branch authentication origin/authentication which means you have created a local branch named authentication here!
git checkout authentication– move into the branch
And now start working on which ever file you want!
3.Commit and Push
Now, commit message should be chosen carefully as it is the only thing that would be shown on what the changes have been made. And after that push your locally created branch to the remote branch.
git add . Add the changes to the staging area, but here is a catch avoid adding files that would create error in the code. Like node modules etc so what you can do is either add those to .gitignore file or add files one by one than using git add ,
git commit -m “facebook authentication Added by Priyanka”, you can add the name of developer too because now you got a person to be responsive for a certain task.
git push origin authentication that is push the changes onto the remote branch
4.Pull and merge conflicts
Now, understand merge process carefully! Say developer A and developer B are working on different modules of the code. And both of them have done their task in 3 days, now the code needs to have both their changes! Thats merging! Here both have pushed their changes onto the respective remote branches.Now, pull the changed by developer B into the branch by developer A and resolve the merge conflicts.
git pull origin Branch B, here we are in local branch A
resolve the merge conflicts manually
git push origin branch A
5. Merge the branch to master
Now, the branch A contains the merged code that needed to be pushed to the master. So, in case of github make a merge pull request whereas in bitbucket etc you can do that by simply merge on the branch to master. Now the master is merged. Also, you would have heard people say delete those branches as they are creating a mess, but dont do that! Keep those branches as it would keep a track for the developer sake who wants credit for the work he did!
Hope, it would have brought lot more clarity from where you started. If you still have an any doubt, leave it in the comment section below. Our team would revert back within 24 hours.
Do Follow our Facebook page https://www.facebook.com/lovebeingengineer/.