Git Daily use Commands

Git Daily use Commands

Clone your git repo

git clone https://github.com/ngdeveloper-projects/SpringBoot-Kakfa

https://github.com/ngdeveloper-projects/SpringBoot-Kakfa is same github repo url. Also note this command check outs the default master (mostly) or default configured branch will be checked out.

Fetch all

git fetch --all

Always fetch first to make sure all the remote branches, tags everything is properly fetched to your loal then you can easily switch/checkout to new branches created recently.

Checkout the branch first time

git checkout -b ngdeveloper_fsdev

ngdeveloper_fsdev is the branch name. This also creates the ngdeveloper_fsdev local branch in local repo.

Checkout the branch (Switching the branch)

git checkout ngdeveloper_fsdev

ngdeveloper_fsdev is the branch name.

Take the latest code from the same branch

git pull

Take the pull from ngdeveloper_fsdev remote origin branch to your local branch which is ngdeveloper_fsdev in our case.

Take the latest code from another branch

git pull origin ngdev_fsdev_main

Take the pull from ngdev_fsdev_main remote origin branch to your local branch which is ngdeveloper_fsdev in our case.

Commit your code

git commit -m "dependency upgraded"

dependency upgraded is your commit message. Always give the meaningful name should also means the actual change you are committing. Some companies follows JIRA ID followed by message (eg: NGDEV-1033: dependency upgraded – if so pls follow the same else it creates some other issues)

Push your code to remote

git push

This pushes your committed changes to your connected remote repo. if you are not sure about your remote repo, check using this command.

Merge the changes from another branch (mostly main feature branch or master)

git merge --no-ff ngdev_fsdev_feature_main

Git Bonus Commands

Check recent commit log

git log --oneline

Show remote origin details

git remote show origin

This shows the repo url of the currently configured as remote origin, meaning all your changes will be pushed or reflected to this remote repo only.

Check the current branch

git branch --show-current

List branches

git branch -a // list all the branches
git branch -l // list all local branches
git branch -r // list all remote branches

Reset your branch

git reset // mixed reset (staged to unstaged)
git reset --hard // this resets to the head of the origin

45 comments

Leave a Reply