Contents

git commands

Contents

Most useful git commands.

intro

Here i summarises the all git commands which is used frequently. It helps developers manage and track changes in their projects.

1
2
# Initializes a new Git repository in the current directory.
git init
1
2
# To configure the the email id in local git repo.
git config --global user.email "your_email_id"
1
2
# To configure the username in the local git repo.
git config --global user.name "your-user-name"
1
2
# To check the user email in git local repo.
git config --global user.email
1
2
# Adds a file or directory to the staging area, preparing it to be committed.
git add .
1
2
# to commmit all the changes.
git commit -m "commit_message"
1
2
# Uploads local repository changes to the remote repository.
git push -u origin main
1
echo "# test" >> README.md
1
git add README.md
1
git branch -M main
1
git remote add origin https://github.com/sumit2011/test.git
1
git clone <repo_link>
1
git add <file_name>
1
git status
1
git config
1
git pull
1
git config
1
2
3
4
5
6
# To show the details of the commits.
git log

git rm --cached filename

git diff
1
git remote -v

Tagging

ex: git tag
to check all the tags

ex: git tag -a v1.0 -m “message” to add a tag

ex: git push origin v1.0 push the tag separately

ex: git show tag_name

Branching

ex: git checkout -b feature1 ex: git switch -c feature2 to create a new branch

ex: git branch ex: git branch –all to check how many branch are available

ex: git log

ex: git switch main to switch to the main brach

ex: git switch - to switch to the prev branch

ex: git branch -d branch_name to delete the branch

ex: git push origin feature1 to push feature1 branch to github

ex: git merge feature1 merge feature1 to main branch

ex: git pull origin main first pull -> merge -> then push

ex: git log –graph

ex: git rebase branch_name

ex: git checkout commit_id go back to prev commit

ex: git stash want to save the code without committing

ex: git stash list show all the stash list

ex: git stash apply to apply the stash