Join us
@kumarkalyan ・ Nov 20,2021 ・ 3 min read ・ 1227 views ・ Originally posted on kumarkalyan.medium.com
Whether you are a professional developer or a beginner in Computer Science, you often have heard the words git and GitHub, as nowadays git has become a daily need in our life as a developer, and is widely used in the software industry.
Since Git is not easy to master as it has many commands but, in this article, I am going to share a few often-used git commands which you must be aware of as a developer.
init
Suppose you have written some code and now you want to initialize it as a new Git repository, or you want to convert an existing, unversioned project to a Git repository, and to do these things you can use
clone
Suppose you want to download all the source code of a particular project which you have found on Github, using the command line then you can use
and this will download all the source code of the given repository URL
add
Suppose you have created a new file or whether you have modified or deleted an existing one and you want to commit these changes to your GitHub repo then you can use
for committing a single file
or you can use
to commit all the changes
branch
Branches are mostly used in Git as it helps developers work in parallel to a particular project. We can use the git branch command for creating, listing, and deleting branches.
Suppose you have a product having features a, b & c, now you want to add a new featured ‘d’ to it. Instead of directly adding the new feature to our main code we can create a branch and add the new feature to it now after all the tests you can simply merge it to the master branch. Here is the list of git branch commands which you can use
will create a new branch
will show you the list of all the branches in a repo
will delete a branch with the given name
status
Suppose you are working on a repository and you want to see what are the changes that occurred, then you will use
to get all the necessary info about
log
Suppose you want to know about the history of what is done to your repository, then use
and it will show you the history of everything that happens to a repository
checkout
suppose there are three branches A, B, C and you want to work on branch ‘A’, and to do so you can use
and this will help you to switch on a particular branch
We can also use it for checking out files and commits.
pull
It is used to get updates from the remote repo. we use
to get the updates from a remote repository (git fetch) and immediately applies the latest changes in your local (git merge).
revert
Sometimes you may want to undo all your last changes to your project, in that case, we can use the
to undo all the changes in a particular commit id
merge
If you’re done with development inside your feature branch and tested your code, you can merge your branch with the parent branch. This could be either a develop branch or a master branch depending on the git workflow you follow, then use the
to merge the new features
commit
Suppose you have done all the modifications and changes to your project and now you want to save all these, then you can use the
git commit -m “Add a commit message”
push
After committing, if your code is ready for production then use the
and this will push all the changes
So these are the basic commands of git you must know as a developer.
Just comment out if I have left something
Happy coding
Join other developers and claim your FAUN account now!
student, Camellia Institute Of technology
@kumarkalyanInfluence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.