Loading content...
Created On: December 2, 2023
Following are some useful commands that are helpful when you work with git-bash.
git init
git config --global user.name <your_github_username>
git congfig --global user.email <your_github_email>git config --global user.name
// it will print your github user name if configured
git config --global user.email
// it will print your github email if configuredtouch <file_name>
// it will create a file with the file_name
git add <file_name>
// it will add the file to the staging area from untracked file area
git add -a
// it will add all the modified files to the staging area from the untracked file areagit commit -m <file_name> <commit_message>
// it will add the commit message to the commit
git commit -a -m <commit_message>
git commit -am <commit_message>
// both these command will commit all the file in the staging area with this commit messagegit checkout -f
// you can undo all the modified files using this command. Git will match all the modified files with the last commit.git log -p -n
// it will show you last n commitsgit diff
// it will compare the files in staging and modified files area
git diff --staged
// it will compare the files skipping the staging areagit rm <file_name>
// it will remove the file with the file_name from staging area to modified area
git rm --cached <file_name>
// it will remove the file from modified area to untracked areagit branch
// it will show all the created branches
git branch <branch_name>
// it will create a branch with the branch_name
git checkout <branch_name>
// using this command you can enter into an existing branch
git checkout -b <branch_name>
// using this command you can create as well as enter into a branch with the branch_name
git merger <branch_name>
// it will merge the current branch to the main branch
// but to merge an existing branch to the main branch you have to first checkout into the branch
git branch -d <branch_name>
// it will delete an existing branch
**
git branch -M main
// it will merge all your branch to the main branch without even checking out a branch
git remote add origin <your_github_repo_url>
//eg; git remote add origin https://github.com/<your_github_user_name>/<github_repo_name>.git
git remote
git remote -v
// using these commands you can crosscheck if the origin is not set//if you are woking with remote repository then it will reccomended to first pull the remote repository before commiting to it. If helps in resolving the merge conflict
git pull
// it will fetch the remote repository and rebase your local repostory
// internally it uses git fetch and git rebase simultaneously
git pull origin <branch_name>
// using this command you can pull a particular remote branch
git push origin <branch_name>
// it will push the locally commited files to the remote repository
git push -u origin main
// it will set the default remote branch to main
git push
// now if you only use this command all the locally commited files will be by default pushed to the remote maingit push origin --delete origin <branch_name>git remote set-url origin <your_github_repo_url>
//eg; git remote set-url origin https://github.com/<your_github_user_name>/<github_repo_name>ssh-keygen -t rsa -C <your_github_email>
// genereting a ssh key
eval "$(ssh-agent -s)"
// evaluating ssh key
ssh-add ~ /.ssh/id_rsa
// adding a rsa id to ssh key
cat ~/.ssh/id-rsa.pub
// showing the rsa key written in the ssh.pub filegit pull --rebase
// it will rebase your local repo branch
git config --global pull.rebase true
// it will enable rebase for every pull you make
// after executing this command you don't have to write --rebase all the time
// you can simply use git pull
ls -lart
// it will make hidden files visible