Here is a list of commonly used git commands
- Initiate a directory as git
git init --bare
- Git clone
git clone url-to-git example URL :user@domain.com:/home-path/username/directory/
- Git status
it will show the files status – modified, tracking , untracked
git status
- Git Add for tracking
git add filename or git add . dot is using to add all files

- Git commit
git commit -m "commit message"
If the file is under git track we can combine both comments in one line like
git commit -am "your-message" or git commit -a -m "your-message" -a to add -m to commit message
- Push your changes to server
git push or git push branch
- Creating branch in git
git branch branch-name
- Switch to branch
git checkout branch-name
- Create a new branch and switch to new branch
git checkout -b branch name
- List all the branches
git branch -a
- Merge Branch
Consider we have master branch A and another branch B,
To merge branch B changes to branch A,
git checkout branch A git merge branch B
if any conflict happened, it will show conflict, we have to do modification and commit again.
- Delete a branch
git branch -d <brach name>
this will delete if all the changes are merged, if you want to use force delete , even not merged,
git branch -D <branch name>
- Upload branch into server at setting head for push
git push --set-upstream origin <branch name>
- Stash all local changes
git stash
- Take back stashed changes – This will take aback all the changes you stashed
git stash pop
- Discard changes on one file
git checkout filename
- Remove local commit and reset to server head – it will delete all the local changes
git reset --hard origin/branch name
- List all the branches push/pull remote origin.
This will show all the remote and local branches and where it is pointing into
git remote show origin
- Fetch and push origin list
git remote -v
- View uncommitted changes made
git diff
- To see all the logs
git log
- To see log with difference
git log -p
- Git log for a single file
git log -p file/path -p will give changes also
- Other options with git log
git log --stat //this will show only number of files changed and number of changes git log --pretty=oneline //show all the changes in one line with head and comment git log --pretty=format:"%h - %an, %ar : %s" //show with name time and commit message git log --author=username //show only one user commit
15,735 total views, 2 views today