Git cheat sheet Opensource contribution
Note: Please correct post if you find mistakes.
//your repository
$ git clone git@github.com:akrabat/zend-validator.git
//if you are cloning a forked repository of someone
// add upstream/parent/original repository as upstream repository
$ git remote add upstream git@repository_url
ex: $ git remote add upstream git@zend/zend-validator.git
//do some changes and then
$ git checkout master/develop/or_specified_branch
$ git pull upstream master && git push origin master
$ git checkout -b hotfix/readme-update
//-b to create a new branch if you have a local branch already then don't use -b
//hotfix = new branch name or we can say prefix like: bugfix/hotfix/feature extra /readme-update : detailed-name
//you should create a new branch or checkout to your local branch you already created. Directly commit to master or other main branch is not recommended.
//-u to also push to upstream directory so we can create a pull request later in original repository
$ git push -u origin hotfix/readme-update
//got to github dashboard and generate the pull request follow the proper format of pull request.
//if your branch is behind with the branch you want to commit let’s say you want your commit to merge to master or develop branch and your hotfix/readme-update is 3 commits behind then you
// have to rebase your current branch with parent branch.
//rebase commands
//first checkout to main branch it could be master or develop branch
$ git checkout branch-name
$ git pull -v
//again checkout to your local branch ex: Feature/my-local-branch
$ git checkout local_branch_name
//now rebase it with parent branch
$ git rebase -i develop
//if you got merge conflict while rebasing with parent branch you have to resolve all merge conflict.
***********Rebase Step***************
//Edit all suggested files by git and then again do git status
command to check changed files. Now follow below commands
$ git add files_names
$ git rebase –continue
// if you get more conflicts then resolve again and repeat from Rebase Step
//if rebase success then do git push. Force the push. If the repository is forked then include -u to also push to origin repository
$ git push origin Local/branch_name –force
The post Git Cheat Sheet – A Collection of the Personal Git Cmds appeared first on Rajesh Royal.
Top comments (0)