A project to help out my fellow dev friends with popular/special Git commands when they're in real need...
git config global user.name <your name>
git config global user.email <your email>
git init
3. At first only master branch is created, so add/stage all files inside the local folder with the following command first
git add <file-name>
git add .
git reset
git reset <file_name> OR git restore --staged <file_name>
git commit -m "your message" <any single file name> or keep blank for commtting all staged file at once
git status
git remote add origin <remote_url>
git remote set-url <remote_name> <ssh_remote_url>
git remote set-url origin <new_remote_url>
git push-u origin master or git push -u origin <branch_name>
git push
git checkout -b <branch_name>
git branch -a
OR to check the local branches only
git branch
git merge master or vice versa
git branch <branch_name>
git branch <new_branch> <base_branch>
git branch <new_branch> <commit_hash_value>
git branch <new_branch> v1.2
git branch --track <new_branch> origin/<base_branch>
alternatively, if the name of the new branch is same as ther remote base branch
git checkout --track origin/<base_branch>
git branch -d <local_branch_name>
in case if you've any pending commits or merge for the branch, then git won't let you delete the branch, hence in that case use to enforce the deletion
git branch -D <local_branch_name>
do use this command with caution
to delete a branch from the remote repo
git push origin --delete <remote_branch_name>
git fetch --prune
git pull --prune
or to update the set of remote branches in local everytime we run git pull or git fetch use
git config remote.origin.prune true
While trying to merge a remote branch to a local empty branch(different/same name), in case if Git refuses to merge unrelated histories use the below command as example
git pull origin master --allow-unrelated-histories
git merge origin origin/master
in case setting any particular remote branch as an upstream branch of a local one, use the below command
git pull --set-upstream-to=origin/<branch-name>
Similar commands can be used during push and creating a local branch straightaway as-
git push --set-upstream-to=origin/<branch-name> and
git branch --set-upstream-to=origin/<branch-name> or
git push --set-upstream origin/<branch-name> and
git branch --set-upstream origin/<branch-name>
git config --global --list
git config --global --unset-all
or use to individually remove configs
git config --global --unset user.name
git config --global --unset user.email
you can use separate Git user name and email for separate project folders in your local environment, use by going inside any specific folder
git config user.name <your user name>
and type
git config user.email <your email>
in case in local during a merge, the info in the HEAD file is at a mismatch between two branches/ in case when terminal showing can not merge due to unrelated histories,use
git pull origin main --allow-unrelated-histories
git merge origin origin/main
in case if you're managing sub-folders inside a repo, while doing git push from the parent/root folder, if you face any issue, use the below command before doing git push
git config http.postBuffer 524288000