[GIT commands] Kickoff

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 :

  1. We have nothing in our local environment, what we want to do is just donwload the code from remote repository
      • First of all, find the l’url of the remote repository (for example github), I’ill take Microsoft TypeScript for instance. We have two types of URLs : SSH or HTTPS. Take one of them. Normally, there is no difference.
      •   
      • Execute “git clone ” command with the url

    • 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.
  2. 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 ”
    • Get the url
    • Add the url to our local repository, make sure we are in the right repository (by default, we give a name origin to our remote url, we can call it another name than origin)

 

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 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s