Now days Git is a popular version control system to manage your source code or more than that. Git gives developer a full control over its source code in terms of creating , editing , deleting , branching and merging of code. It plays an important role in terms of developers who works in large teams especially open source developers who are reliable on this to get there own copy of source code and play with to write there own patches. 🙂
You will find many online tutorials what is git , how it is Distributed, git vs svn, but very few of them will focus on how developers are using it and flow of using it.In this post i will try to focus on git flow. True!! Git is Distributed Version Control System(DVCS).But what’s that DVCS?
Well, Distributed version control system depicts in layman’s terms the flexibility to clone project from repository have mouldability to work on similar copy of project on their local system without accessing the internet.Now, what is the difference between github and git. Git and Github are not same. Github is a hosting service which provides the interface to access the projects/ repository which uses Git tool.Let’s discuss if you are a beginner in development and want to work on a opensource project .
Getting started with Github
Step 1. Create a Git-hub account using your email id and a strong password.
Step 2. Access your git-hub account and search for the project you want to contribute for. For example you want to contribute to NodeJs project.
Step 3. Now , you can see many NodeJs repositories select the one you wants to contribute to. Click the link which you have selected and then “Fork” the repository. Why “Fork”? Because , when user click on Fork it will clone the github repository to your account on the github server side not on your local system.In this diagram developer forked a repository to start experimenting with his code without even interfering to original repository.
Step 4. Now, developer can clone the repository locally and start working on it , say editing a file and save it.Developer can add his code into its local repository .
To clone repository from github type : git clone https://github.project-name-of repo.git
Step 5. Once developer done with the code changes he can commit and push changes to his forked repository.
Step 6. Now, developer want to propose the Original repository maintainer to consider his code in the original project. For this developer needs to create a Pull request . In pull request developer proposed his code to merge in the original repository. It include certain steps before the code merged to original repository.
- Creating new pull request
- Send it for review to original maintainer
- Change branch to compare code changes source to destination branch
- There can be discussion over the code changes which will be logged on github
- After reviewing maintainer can merge the code to the master branch or destination branch
Using Git on your local repository
- To clone the repository : git clone repo-url
- To add new file to the branch : git add file
- To commit changes to the file : git commit -m “message of commit” file
- To commit changes to your original repository : git push file origin/master
- To remove file from repository :git rm file , git commit -m “removed” file
- To remove file from repository but not from the local : gir rm –cached file
- To view all the logs of your local repository : git log
- To view history of the repository : git hist
Some advance git commands (Used very less 🙂 )
- To review the lost commits : gt reflog
- To revert the branch to its earlier stage, first checkout the repository and then do hard reset : 1. git checkout repo 2. git reset –hard (revision number)
Hope you enjoyed the simplified approach to learn git and github !! 🙂