Working with GIT Commands
Preface
If you are a professional software coder then you must have come across the need of having source management and source control. Though there are many options available in market but the GIT wins with the feature it supports.
Here i would be listing frequently used commands with git which we need to execute almost on daily basis.
Before We go the list of commands make sure git software is downloaded and installed on your system.
Linux : sudo apt install git-all
Mac :brew install git
Clone a stash branch to local git
git clone <repoURL>
Creating a stash branch
Once you have JIRA for User Story , You can create a new branch out of develop repo from JIRA itself.
Or alternatively you can create branch with below step as well.
- git checkout develop
- git checkout -b <New Branch Name>
Make a commit on local
git status
git add file1
git commit -m “message related to what you have added/changed” file1 file2
Push to stash
git status
git push origin HEAD
Raising Pull Request
- Go to your bitbucket branch which needs to be pulled
- Under Navigation menu click on to Pull Requests
- Click on to Create Pull Request
- Select Your branch as source and destination branch , and click on Continue
- Provide details of changes along with the Reviewers.
Reviewing Pull Request
- bitbucket has nice Interface to show Overview,Diff’s and Commits for Reviewer where one can see input notes provided by author, the changed/added line of codes, various commits done.
- Reviewer gets option to comment, create task or suggest inline updated code to author.
Merge branch to develop
git checkout develop (or the branch to which you wish to merge the code)
git pull
git checkout <your branch> (or the branch from which you wish to merge the code)
git pull origin develop
— — Make changes to resolve the conflict , if there re any
— — git commit
— — git push
From bitbucket merge your changes to develop (after making sure diff shows correct changes)
Delete Merged Branch
- To Delete Local branch
- git branch -d <branch name>
- $ git -d <branch name>
- To Delete remote branch
- git push -d origin <branch_name>
- Example : $ git push -d origin “bugfix/XXXX”
Renaming a GIT branch
git branch -m <new name for branch>
Revert All Modified Files
git checkout -f
Undo a git add — remove files staged for a git commit
git reset filename.txt
Remove untracked files
git clean -fd
Checkout Remote Branch
Git checkout remote branch let’s us switch to (and work on) a remote branch, just like we’d switch to a local one
- First, fetch the remote branches:
git fetch origin
- Next, checkout the branch you want. In this case, the branch we want is called “branchxyz.”
git checkout -b branchxyz origin/branchxyz