Regular Flow
Git Workflow
Clone a repo
↓
Create a Branch & switch
↓
Make code changes
↓
Stage the changes
↓
Commit the changes
↓
Push the changes
↓
Create a Pull Request(PR)
1. Cloning a repo
To clone a repository locally, use the repo clone
subcommand. Replace the repository
parameter with the repository name. For example, octo-org/octo-repo
, monalisa/octo-repo
, or octo-repo
. If the OWNER/
portion of the OWNER/REPO
repository argument is omitted, it defaults to the name of the authenticating user.
gh repo clone REPOSITORY
You can also use the GitHub URL to clone a repository.
gh repo clone https://github.com/PATH-TO/REPOSITORY
Refer troubleshooting cloning errors doc if required.
2. Creating a Branch
Description | Commands |
---|---|
create branch | git branch <branchName> |
create branch & switch | git checkout -b <branchName> |
switch branch | git checkout <branchName> |
rename branch (checkout branch to be renamed) | git branch -m <newName> |
rename branch (no need to switch branch) | git branch -m <oldName> <newName> |
create & switch a branch from another branch | git checkout -b [newBranch] [createFrom] |
set the default remote branch for your current local branch | git push --set-upstream origin [branchName] |
pushes all the branches to the main branch | git push origin |
pushes your master branch to the origin | git push origin master |
Examples
3. Stage the changes
git add [filename]
selects that file, and moves it to the staging area, marking it for inclusion in the next commit. You can select all files, a directory, specific files, or even specific parts of a file for staging and commit.
- Stage a specific directory or file
git add <path>
- Stage all files (that are not listed in the .gitignore) in the entire repository
git add .
- Interactively stage hunks of changes
git add -p
4. Git Commit
git commit
creates a commit, which is like a snapshot of your repository. These commits are snapshots of your entire repository at specific times. You should make new commits often, based around logical units of change. Over time, commits should tell a story of the history of your repository and how it came to be the way that it currently is. Commits include lots of metadata in addition to the contents and message, like the author, timestamp, and more.
git commit -m "update the README.md with link to contributing guide"
Please refer Commit Messages for writing proper messages.
5. Git Push
git push
updates the remote branch with local commits. It is one of the four commands in Git that prompts interaction with the remote repository. You can also think of git push
as update or publish.
git push
6. Create a Pull Request
Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch.
Go to git repo and Create a PR from there.