In this article i will list all Git commands used by developers on daily work life. Git is a powerful source management system, and very popular. I used TFS for couple of years, but when i got chance to use Git, i found that i was missing really a robust, very easy and powerful source management practice.
So I have listed here all git commands:
Initialize Git Repository
To initialize a new Git repository, use this command:
This will create a .git folder in the current folder. On windows it’s a hidden folder.
The best practice is to create a new branch for each feature or bug fix. To create a new branch, use below command:
git branch <branchname>
This will create a new branch.
Create a new branch from specific commit:
git branch <branchname> <commit_id>
Create a new branch from a tag
git branch <branchname> <tag>
This will create a new branch from a tag.
To push a branch to remote:
git branch -u origin <branchname>
This will push the branch to remote repository.
After you created a new branch, you need to switch or enter into that branch. For that git offers checkout command:
git checkout <branchname>
After that you can see git will indicate the new branch as the current branch.
Branch and Checkout in one command
Above i showed two separate commands to create branch and then checkout to that branch. We can do that thing in one single command:
git checkout -b <branchname>
Easy one liner.