Wednesday, July 12, 2017

Developing with git by forking a repository

When collaborating with Git, the “fork and branch” workflow is a common way of collaborating on open source projects  and, also useful for internal project development to give code owners better control on managing code commits from the bunch of developers. Required steps to this workflow are given as below:

First time setup

1. Fork a GitHub repository
Go to the GitHub repository in your browser and Click the Fork button on the upper right-hand side of the repository’s page.

2. Clone the forked repository to your local system
Copy the URL of the forked repository and run the below clone command in a folder at your machine(Where you will at sore the local copy of your repository):
$git clone <git_fork_url>

3. Add a Git remote for the original repository
$git remote add upstream <git_original_url>
4. List Git remote List
$git remote -v

Routine Work for development

1. Create a feature branch in which to place your changes
$git checkout -b feature/<jira-id-title>

2. Make your changes to the new branch.

3. Commit the changes to the branch.
Use the git add and git commit commands as required

4. Sync with latest upstream code
Run below commands on the repo:
a. $git fetch upstream
b. $git merge upstream/develop (for Dev branch merge) or
$git merge upstream/qa (for qa branch merge)

5. Push the branch to GitHub
$git push origin feature/<jira-id-title>

6. Go to the browser and create a pull request from the new branch to the original repo. Please make sure to add reviewers.

7. Clean up after your pull request is merged
a. $git pull upstream develop
b. $git branch-d feature/<jira-id-title>
c. $git push origin develop
d. $git push --delete origin feature/<jira-id-title>

8. Clear history of a repo
git checkout --orphan tmp-main # create a temporary branch
git add -A  # Add all files and commit them
git commit -m 'Initial commit'
git branch -D main # Deletes the main branch
git branch -m main # Rename the current branch to main git push -f origin main # Force push main
branch to Git server

No comments:

Post a Comment

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...