Important Git Commands that I learned
Git is the popular open source version control system. It is an important terminology for all developers to manage their code for the development. Nowadays Software field is impossible without Version Control System.
Here I am sharing some commands which I learned from my university, which you can understand the fundamentals of git ,how to create repository in github and how you can push your code to your repository that you have created.
1. Creating a new git Repository
‘git init’ is the command that we use to create a local git repository with a default branch called master branch. After this command we need to create a remote repository and have to connect this local repository to github.
2. Creating a new remote Repository
go to https://github.com/ and create a new remote repository with any name you need. But you can’t create a new repository with existing repository name. You can make your repository as a public or private. Most of the companies make their repositories as private because of their safety.
After creating your repository, you can see the interface like below and there will be some commands which is useful for the developer.
3. Git Add
‘git add filename’ means it will add a change to the particular file that the file should be update if you do any changes. The command ‘git add .’ is used to add changes for all files which are in our local repository.
4. Commit changes
‘git commit -m “commit”’ is simply the changes what we have in our code. It captures the current changes that should be updated to the repository.
5. Git stage
If you want to commit the changes separately like if you have 8 files and we need to commit changes for only 3 files, you need to stage the files with the command ‘git stage index.html’.
Once you create a repository, it will be created with a default branch called ‘master’. If you need a new branch, you have to type a command ‘git branch branch name’. If you need to switch into the new branch you have to type ‘git checkout branch name’ and type the code.
‘git push origin master’ is the command that used to push our local repository codes into the remote repository in github. For example, if you want to push your content to the new branch, you can type ‘git push origin branch name’ and push your code. After you pushed, your local repository files will be published in github.
Git is like a deep sea. I have shared only the basic and important commands, but we can learn bunch of things about git and I know it is not an easy thing, but once we learned, we will be a good fit to enter into software world.