Ramesh Kannan
Senior .NET Full Stack Developer
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.
Here are some basic Git commands you need to know.
git clone {url} — Here {url} represents the Git Repository URL
git clone https://git.com/example/example-repository
By default, this command clones the default branch of the repository (in most cases, master). To clone a specific branch:
git clone {url} -b {branch_name}
git clone https://git.com/example/example-repository -b development
To change the local working branch, use the checkout command.
git checkout origin/{branch_name}
git checkout origin/master
To fetch all changes from remote, use the fetch command.
git fetch --origin
NOTE: This command will not merge the changes into the local branch.
To update the local branch:
git pull
To merge changes from another remote branch:
git pull --no-rebase "origin" {branch_name}
git pull --no-rebase "origin" development
This command pulls all changes from the development branch and merges them locally.
List the files you have changed and need to stage or commit:
git status
To stage your files, use the add command.
git add {file_path}
git add test/file.mdgit add {folder_name}git add *.cssgit add .To commit the staged changes:
git commit -m "{message}"
git commit -m "Test commit"
NOTE:
- A commit message is required for all commits.
- Changes will not be pushed to remote unless you explicitly push them.
git push
To discard all local uncommitted changes:
git reset --hard
To delete all untracked files:
git clean -df
Options:
-d — Recurse into directories and delete.-f — Force delete.