Git Basics:- Commands you should know to push your first project

What is Git?

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Is Git and Github are same?

Simply NO! Git is a version control system that lets you manage and keep track of your source code history while GitHub is a cloud-based hosting service that lets you manage Git repositories. If you have open-source projects that use Git, then GitHub is designed to help you better manage them.

Git Configuration

This command is used to return a list of information about your git configuration including username and email.

git config -i

Setup Git username

This command sets a name that is identifiable for credit when reviewing version history

git config --global user.name “[firstname lastname]”

Setup Git useremail

This command lets you setup email address you are going to use in your commits.

git config --global user.email “[valid-email]”

Initialize a git repository

Everything starts from here. Suppose you are in your local system ,you need to first initialize a new git repo locally in your project root.

git init

Adding files

Now next step to add files in the staging area.If you want to add all the files use some whitespace and . to stage all files and if you want to add a particular file only write name of file. for e.g file1.txt

// All files
git add .
// Only single file
git add file1.txt

Check Repository status in git

This command is used to show the status of current repository including all the files whether staged, unstaged or untracked.

git status

Commit Changes you made to your Git Repo:

Now it's time to commit those files which you have added. A commit message must be added with it to tell the short summary of changes to the reader.

git commit -m"your message"

Add a remote origin :

Now you have saved and commit those files in your local repo but it's not going to update directly on github so for that you need to add your remote repo url. The git remote command lets you create, view, and delete connections to other repositories. This command will add a remote repo to your local repo (just replace repo_URL) to your github remote repo link.

git remote add origin repo_URL

This command will lists all the remote repositories for your local repository .

git remote -v

Push changes to remote repository

When all your work is ready to be saved on the remote repositroy, you can push all your changes using the command.

git push -u origin master # pushes changes to origin

Now the git push command pushes the changes in your local repository up to the remote repository you specified as the origin.

Now if you refresh your github repository you can check that all your files are there that you have pushed.

Hurray, Your first project has been uploaded to GitHub.

These are some basic commands that you can use to upload your project in github. Please like and share if you found it helpful.