Git Basics

gitbasics

Set up name and email info

First, you need to set up a default name and email. Else, git won’t let you commit.

Every time you commit, your user name and email is in part of the commit info. This allows git to show who did what when working in a team. That’s why user name and email are required. (you can use the random name and email if you want)


# set up default name and email
git config --global user.name "test"
git config --global user.email "test@test.com"

The above will create a file at ~/.gitconfig. You can run these commands again to change. (you can also edit the file directly.)


git help

Git commands for new project


git init

Create a git repository in current dir. This will create a directory named “.git” in current dir. The “.git” directory holds all git’s internal data.


git clone url

Clone the repository from url_or_path to current dir. “clone” basically means copy. The URL can be a local directory/folder path that contains “.git”.


git status

Show current status. (that is, the list changed files.)


git add .

Add changes from current dir to the local repository’s staging area.


git commit -m "message"

Commit changes after add, to the local repository. The message is a short description of the changes you made.


git pull

Pull from remote to your local repository.


git push

Push your local repository to the remote.

Note: All git operations are done to the local repository. The only exception is git pull and git push.

About the Author: Pankaj Bisht