Wednesday, 7 August 2019

Git Create branch, create tag, remove local and remote branch, merge branch, solve merge conflicts

Create a local branch, and push to remote
/* clone your project */
git clone <project_repo_url>
/* Check out master branch */
git check out master
/* Create a local branch based on master and swith to that branch*/
git checkout -b <branch_name>
/* See which branch, you are currently at, should now be <branch_name>*/
git branch
/* Commit your local changes to <branch_name>, this step can be skipped if there are no changes */
git add .
git commit -m "my local changes to <branch_name>"
/* Push branch up to remote */
git push -u origin <branch_name>


https://confluence.atlassian.com/bitbucket/branching-a-repository-223217999.html
https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow
https://stackoverflow.com/questions/22098634/how-to-do-a-branch-per-task-strategy-with-git


Merge contents of  branch_b to branch_a

/* Check out branch_a branch */
git check out <branch_a>
/* Merge with contents in branch_b */
git merge <branch_b>
/* Push merged changes to remote*/
git push


https://confluence.atlassian.com/bitbucket/branching-a-repository-223217999.html


Resolve merge conflicts and push to remote
/* Check out branch_a branch */
git check out <branch_a>
/* Merge with contents in branch_b */
git merge <branch_b>
/* Merge conflicts encountered*/
/* Check the conflicts file  */
samplefile.txt
/* This means what ever contents branch_a has that has conflict with branch_b */
<<<<<< Head
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxx
/* This is what branch_b has that conflicts with branch_a */
>>>>>>>>>>branch_b
xxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxx
/* Resolve conflicts, and remove <<<<<Head .... >>>>>branch_b, in conflicts file */
/* Commit and push to remote */
git add .
git commit -m "my merged contents from branch_b to branch_a"
git push

https://help.github.com/en/articles/resolving-a-merge-conflict-using-the-command-line


Add tag to a branch

/* Check out branch */
git check out <branch_name>
/* Create tag, -a to add description to tag*/
git tag <tag_name> -a
/* Push tag to remote*/
git push origin --tags

https://stackoverflow.com/questions/18216991/create-a-tag-in-a-github-repository


Delete local branch, and delete remote branch

/* Check out any branch that you are not gonna delete. Git will not allow you to delete a branch that you are currently on  */
git check out <branch_name>
/* Delete branch locally -D flag is force delete */
git branch -D <branch_name_to_delete>
/*  Delete remote branch */
git push origin --delete <branch_name_on_remote_to_delete>
https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely



No comments:

Post a Comment