To start a git project, it is better to know some useful commands in order to understand how it works. This article allows me to memory some useful git commands.
I suppose there is aleready a git remote repository (something like github, bitbuckets, gitlab etc.) and already done “git init” in local directory.
So let’s begin.
Two things we have to consider :
- We have nothing in our local environment, what we want to do is just donwload the code from remote repository
- If we type entrer, we’ll get something like bellow, and the command will create a repository which is called : TypeScript, it is also the name of your local project.
- And I suppose that we have modified something in the code and want to save them
- First check out the difference that we modified by “git status” (for example the file README.md)
- To save them, in git, we have to do three things : “git add”, “git commit” and “git push”
- “git add” allows us to “prepare” the code that we have just modified, technically, it will update the index of your local files and prepare the content staged for next commit.
- Once it is prepared by git, we can commit it, which will store the current contents of the index with a message of course : (the storage is ready but is not yet sent to remote repository)
- Once we finish all our works (in real life never), and we decide to send(or save) our works to remote repository, we will have to do a “git push” :
- These are the basics commands that we could use for git.
- We have already some code in local, and we want to add remote repository link to our local folder and prehaps save our code in the future. What we have to do, instead of doing a “git clone”, we can do a “git remote add ”
Of course, Git allows us to manage more complicated version control, this article is just for the beginner and for memory. Ignore it if it is trop null 😉