Top 5 commonly used git commands

  • Git Clone
    Git Clone is a command for fetching source code from a remote repository. It makes an identical copy of the latest version of a project in your local repository. The command is:
git clone <url> //url : Get the URL from the project which usually starts with https://

in the above image, we are cloning using url. If your repository is empty, you will see a warning. It is git’s way of informing you about the project. Nothing to worry about. The command will create a new folder (ex: “gitblog”). If you would like to provide different repository name than remote repository name, then you should write below command.

git clone <url> <local_repository_name>

for the above clone command, the local repository name will be “local_git_blog”

  • Git Add
    When we like to add our changed file into new commit, we should use this command.
git add <file_path>  //this adds the single file for the next commit.
git add -ignore-removal //Stages only new and modified files only.
git add -u //Stages only deleted and modified files only.
git add . //Stages all the files(new, modified, deleted)

the  above image shows that two newly created files on our local repository is ready for commit. You can check by doing git status which shows what are the list of the files which is needed to be committed.

  • Git Commit
    This is one of the most used git commands. After we finish a task or issue in development and we want to save our changes, we can you this command. We should always write a message to explain what these changes are. Important thing to note here is your changes will be saved locally only. It will not be visible on remote repository.
git commit -m "message"

Above image shows that two files which I added for the commit are now committed. It is very important to provide meaningful message to your commit so you can quickly understand what that commit represents.

  • Git Push
    Once you finish committing your changes, we would like to sync our changes to the remote server.
git push <remote> <branch-name>

The command will push all my commits to the remote repository. On the history of the file, you can see our commit with the provided message.
If your branch is new in your local and does not have the corresponding branch on remote server then we should first create a branch on remote server and send our changes to the remote server. The command to use at that point is

git push -u origin <branch_name>
  • Git Pull
    This command is a combination of fit merge and git fetch. This command gets the changes from remote repository and merges changes into our local branch
git pull <remote>

By using this command, you can fetch all the changes from your remote branch to the local branch. It shows what are the files which is changed on master like index.html and trail.html.

I hope this post was helpful to you. If you like my post, follow me @twitter/andramazo.

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top