List of important commands for git CLI users
- git clone - clone project to local machine
- git status - check current status
- git add ./filename - add new changes locally
- git commit -m message - commit new changes into bitbucket
- git push - will send changes into bitbucket
- git pull - get updates from bitbucket to local repository
- git branch - view current working branch
- git branch dev - create a new branch called dev
- git checkout dev - switch into dev from current branch
- git push --set-upstream origin dev - push changes to dev branch
- git remote -v - find remote repository url
- git remote set-url origin https://github.com/suji/TestApp.git - change remote repository url to a new one
- git merge --abort -abort current merge command
- git remote rm origin -remove origin url of repository
Create a new repository on the command line
- echo "# TestApp" >> README.md
- git init
- git add README.md
- git commit -m "first commit"
- git remote add origin https://github.com/sujith/TestApp.git
- git push -u origin master
Push an existing repository from the command line
- git remote add origin https://github.com/sujith/TestApp.git
- git push -u origin master
When you add new file(which has already in the git repository) to git ignore file, run below command to ignore it.
- git rm -r --cached .
- git add .
- git commit -m 'removing ignored files'
Configure git for the first time
- git config --global user.name "Sujith Delpachithra"
- git config --global user.email "sujith@g**.lk"
If your code is already tracked by git then set this repository as your "origin" to push.
- cd existing-project
- git remote add origin http://bitbucket.mobitel.lk/suji/testapp.git
- git push -u origin --all
- git push origin --tags
You can use the git cherry-pick command to merge one branch to another.
- git cherry-pick d4d8e7c
(Replace d4d8e7c with relevant commit id you need to merge from another branch to this branch)
You can revert to previous commit.
- git reset --hard <commit_id>
- git push -f origin staging
Let's say you want to merge local development branch into local staging branch.
Then first you need to checkout stating branch with this command.
- git checkout staging
Then you can do merging with this command.
- git merge development
How to merge development branch changes to staging branch.
1. First checkout to staging branch
2. Then execute below command
- git merge development