GIT Commands using the terminal

In this blog you will find some basic git commands that can be used via the terminal.

Step 1: Go to the directory that you have your project folder which is to be uploaded to git(figure I) and type cmd and press enter and the command line will open up(figure II).

Figure I
Figure II

Step 2: Configure your git username and email

Figure III
Figure IV

Step 3: You have the ability to add all the files in the project folder at once using the command (Figure V) git add .

Figure V

Or if you wish to add a single file you can use the command git add [file name with the extension] Check the Figure VI

Figure VI

Step 4: Commit the files to version control (Figure VII)

Figure VII

Step 5: If you have not created a git repository already you can Go to git hub and create a new repository.

By navigating to your repositories and clicking on new and after giving a name for the repository your new repo will be created. You can also make your repository either public or private.

Step 6: Defining the remote repository using the terminal

$ git remote add origin https://github.com/username/new_repo

Step 7: Push the project to version control

$ git push -u origin master

Some Other Useful Commands

  • Check status → git status
  • Display all the commits → git log
  • Specify a branch that you need to push → git checkout [branch-name]
  • View all the branches → git branch
  • Create a new branch → git branch [new branch-name]
  • Switch to another branch → git checkout [branch-name]
  • Merge a branch with the master branch → git merge [branch-name]
  • Pulling a project from git to your instance → git pull
  • Analyze the current state of your git repo → git diff
  • View all changes of tracked files which are present in working directory → git diff HEAD
  • Deleting a branch → git branch -D [branch-name]

--

--