10 Git commands that you should know
10 Git commands that you should know as a web developer.
Here are some important Git commands that you should know, as a web developer. I would recommend you to learn git at soon as possible. It makes your life easy.
- Git is a version control system for tracking changes in your code history. Lower left ballpoint pen
Initialize git repository
git init
-> This initialize new empty git repository. This command needed only once at the git setup time in project. This creates .git sub-directory inside your project's root directory. This subdirectory contains all the metadata information related to version control.
Setup name
git config --global user.name "your-name"
-> Git require your identity before making code push. To configure your identity you have to set your name using this command.
Setup email
git config --global user.email "your-email"
-> This command will set your email address which will be recorded to commit history of repository for later use. Make sure to add right email.
Adds up your changes
git add .
-> This command indexed all the objects of project and recognized them so that git can commit. Think of it as objects that we want to transfer.
Commit added changes
git commit -am "Initial commit"
-> This wraps all files that are indexed by git add command. This command require message, so you can remember, what was the purpose of commit or about what feature this changes was made. Think of it as a Box contains all objects to be transfer
Push on remote repository
git push origin master
-> This command will push the local contents which are committed to remote repository. It will push all the commits with internal objects to remote repository. Think of it as a postman holding a Box that we have to transfer.
It also creates remote branch if that pushed branch not found on remote repository.
Show history of previous commits
git log
-> It will show all the commits in descending order. It will show all the information about commits like commit author name, date of commit and their date.
Remove uncommitted changes
git stash
-> It will remove all your changes made in your local directory. Therefor be careful with this.
Create a branch
git checkout -b branch_name
-> This command creates a clone of a branch in which you are currently in. So, assume if you are in main branch and you want to create a copy of main branch then git checkout -b master_copy
command will create a clone of main branch with name master_copy.
Change remote origin
`git remote add origin https://github.com/user/example.git
-> This command modifies the remove repository URL. This works like an address to your repository where you want your code to be retain. In short it instruct git that where to push your changes.
-> You can verify whether remote URL is updated or not using git remote -v
command. This command show 2 URLs.
-> origin https://github.com/user/example.git (fetch)
- Git fetch code from this repository.
-> origin https://github.com/user/example.git (push)
- Git push your code to this repository.
Thanks for reading this article. If you like this, then you can follow me and don't miss the upcoming web development and programming tips and articles like these.
You can find me on twitter.
Twitter: @iamharis010