This documentation provides a quick setup process of Git and a few useful commands.
- Download git application from https://git-scm.com
- Install it on your computer.
- Open the terminal (Mac) or Poweshell (Windows).
- Once done, run the following command to check the git version.
git --versionor
git -vπ Output
The following commands allow you to set username and email address globally. π€
git config --global user.name "Your Name"
git config --global user.email "Your Email"You can also set specific username and email address for your current project. πͺ
git config user.name "Your Name"
git config user.email "Your Email"git config --global user.name
git config --global user.emailThe following command allows you to initialize a fresh local git repository to your project.
git initThe following command will display the current status of the added/updated/deleted files.
git statusgit add -A
git commit -m "your_custom_commit_message_in_here"
git commit -am "your custom_commit_message_in_here"
git remote add origin "git_remote_repository_url"
//set upstream. (rename the remote from origin to upstream)
git remote rename origin upstream
// Using -u, you can set the upstream branch for the current branch. e.g main
git push -u origin main
// Pull any changes from remote main branch
git pull origin main
git clone "git_remote_repository_url"
// Clone a specific branch from a remote repository
// -b means, Gitll will check out the staging branch right after cloning.
git clone -b "staging" "git_remote_repository_url"
git reset "index.html"
// Check current origin
git remote -v
//Set a new origin.
git remote set-url origin "git_remote_repository_url"- List of all branches.
git branch -a- Show current branch.
git branch --show-current- Create a new branch and switch to that branch
git checkout -b "new_branch_name"- Rename current branch.
git branch -m "new_renamed_branch_name"- Delete a branch. (locally)
git branch -d "deleted_branch_name"- Delete a branch. (remote)
git push origin -d "<BRANCH_NAME>"- Switch to a branch.
git checkout "branch_name"- Merge a branch.
git merge "branch_name"Using git tag commands you can easiliy mark stable version of a project. It creates an image of your git repository. To tag a branch, you need to checkout a stable branch. e.g main
git checkout branch "main"
git tag v1.0git tag -a v1.0 -m "this is a stable 1.0 version of my project"git taggit push origin v1.0git push origin v1.0 v1.1git push --tagsgit tag -d v1.0git tag -d v1.0 v1.1git push origin -d v1.0Using the following commands, you can check all previous commits hash, commits date, author.
git loggit log -3Output
git log --graphOutput
git log --onelineOutput
- Run the following command. (Check origin name, for mine it's the main)
git pull origin main --allow-unrelated-histories- After running this code a popup window will appear. Press 'wq' from keyboard.
- It's done. Now you can push your code to the remote repository.
git rm -r --cached 'FOLDER_NAME'If you accidentally added a Git commit message or would like to update the last Git commit message, then use the following command:
git commit --amend -m "Updated commit message"- Create a new directory
mkdir YOUR_DIR_NAME- Create an empty file.
touch YOUR_FILE_NAME- Read A File.
cat YOUR_FILE_NAME- Create a directory
mkdir YOUR_DIR_NAME- List of folder and files in a directory.
ls YOUR_DIR_NAME- Create an empty file.
echo YOUR_FILE_NAME- 
Md Mahbub Alam Khan 



