Git Command for day to day development for beginners

Git Command for day to day development for beginners

·

2 min read

Git - Introduction

Git is a distributed version control system that helps developers collaborate on projects of any scale.

A distributed version control system is a system that helps you keep track of changes you've made to files in your project.

Git makes collaboration easy. Everyone on the team can keep a full backup of the repositories they're working on on their local machine. Then, they can safely store the repository in a single place like BitBucket, GitHub or GitLab.

Often used Git Commands

1. To initialize a Git repo:

The first step is to initialize a new Git repo locally in your project root.

git init

2. To add all files in the staging area in Git:

If you want to add all files in your project to the staging area, you can use a wildcard or --all option and every file will be added for you.

git add .

( or )

git add --all

3. To check a repository's status in Git:

The status of the current repository including staged, unstaged, and untracked files. are shown using below command.

git status

4. To commit changes with a message in Git:

Commits keep track of our progress and changes as we work. Git considers each commit as "change point" or "save point". It is a point in the project you can go back to if you find a bug, or want to make a change in the code.

When we commit, we should always include a message.

By adding clear messages to each commit, it is easy for yourself (and others) to see what has changed and when.

git commit -m "your commit message here"

5. To add a remote repository in Git:

This command adds a remote repository to your local repository (just replace repo_here with your remote repo URL).

git remote add origin URL specifies that you are adding a remote repository, with the specified URL, as an origin to your local Git repo.

git remote add origin https://<github.com/your account in github>/<repository name>.git

( or - With Github Personal token)

git remote add origin https://<username:github_token@github.com>/<your account in github>/<repository name>.git

6. To see remote URLs in Git:

You can see all remote repositories for your local repository with this command:

git remote -v

7. To push a new branch to a remote repo in Git:

If you want to push a branch to a remote repository you can use the command below. Just remember to add -u to create the branch upstream:

git push -u origin branch_name