Git is a distributed version-control system for tracking changes in source code during software development.
Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. Its current maintainer since 2005 is Junio Hamano.
Git is free and open-source software distributed under the terms of the GNU General Public License version 2.
Before going to use git we want to check whether your system has git.
For checking whether you have git type the following,
$ git --version
For installing git in your system
$ sudo apt-get install git
Then open up the terminal and update your git account.
$ git config --global user.email "[email protected]"
$ git config --global user.name "Your Name"
For clone a git repository use,
$ git clone https://github.com/....
For checking the status of your edit,
$ git status
For adding your edit to the origin/master branch,
$ git add .
For committing your edit to the master branch,
$ git commit -m "Some random message"
For pushing your code to remote server,
$ git push
If you got conflict error the update the git repository by,
$ git pull
and call
$ git mergetool
for fixing the conflict.
Use the default conflict resolver meld
for graphical conflict resolving.
Here were are going to do some action in Github.
The main steps in done in this program
- Fork the repository
- Edit the content
- Commit your edits
- Push your edits
- Create Pull Request (PR)
First fork the repository from the source by clicking on the fork button on the right-most part of the repository.
Now you have got a duplicate/fork of the repository.
Now we need to save our repository to our local system or computer. We need to copy the URL of your repository and do following command.
$ git clone https://github.com/examplerepo
Now we have successfully saved the repository to your system.
Edit your files by using text editors like gedit, sublimetext,etc.
**Note : ** Before this you should be in the root of the local clone of the repo.
It is recommended to commit every edits you do as it will easier for you to return to previous code. So for committing your edits do the below code.
$ git add .
$ git commit -m "Edited file!!"
After editing your file, we now have to update your repository in the remote server ,i.e in Github's server. For this we use push
command.
$ git push
After this , we have successfully updated the repository in the server.
Note : At this stage you may have encountered an error due to mail privacy. To solve this just uncheck the Email privacy in the Email Tab in your Profile Settings. For more info regarding this error, click here.
Now we have reached to the last and important stage of our session. Creating pull request is basically adding your new features to the master branch of the repository.
To create PR, click on 'New Pull Request' in th 'Pull Request' Tab in your repository. Then compare both of your edits and apply for PR. Now a dialog box will come and add some details. Then click submit.
Now you have made your Pull Request or simply your PR !!
Upstream refers to the main repository from where you forked. You need to mention the URL of the main repo to pull changes from it :
git remote add upstream https://github.com/example/examplerepo.git
Now you can pull changes from the master
branch of the main repository :
git pull upstream master