it – Get it today!
Git is open source distributed version control system.
Mostly is used to store the content of code on which the developer’s is working. Each developer having different modules of code to do in a same project, so to merge code on same server and make sure to have no code conflicts between the developers.
The code in git keep changing as many developers can add code to it parallel by some features of branches and merge provided by it.
Git having a remote repository which is stored in server and each developer has their local repository stored in computer.
Let us make it more clear and learn how to use it.
Firstly, download and setup git on your local computer.
Commands to set git on your project by using Command Prompt for Windows and Terminal for Linux/Mac
- Go into your local project folder and add a local git repository to project
- Set your username, email and password to protect your repository
git config –-global user.name “example-name”
git config –-global user.email “firstname.lastname@example.org”
git config –-global user.password “example”
- To get the necessary information about the current branch like
- Whether it is up to date
- Whether anything to commit, push or pull
- When we add, modify or delete in code it will show in red marks, so you just must add those files in git accordingly.
To Add Single File:
git add filename
To Add All Files:
git add .
git add -A
- After adding those files, you want, it will change to green and now you can commit those files with a message so, you will get a unique id every time you commit
git commit -m “”
- Now you can easily push/uploads the commits to remote repository
however, if branch is newly created then use the following command
git push --set-upstream <remote> <name-of-your-branch>
git push -u origin <branch-name>
- To get the updated code from remote repo, this operation may create conflicts, so you must solve it manually.
git pull or git pull origin <branch-name>
Every developer should know the above commands, which is basically used to set your project on remote repo.
The other commands are:
- git branch
- git branch <branch-name>
- git checkout <branch-name>
- git clone <https://name-of-the-repository-link>
- git merge <branch-name>
- git log
Those above commands are also use accordingly to your need.