Git
Basic Git workflow covering the essential commands for typical tasks.
Basic workflow
Command | Description |
---|---|
| Clone a remote repository. |
| Show the current state of the working directory and staging area. |
| Stage specific file changes. |
| Stage all changes in the current directory. |
| Commit staged changes with a descriptive message. |
| Push changes to the specified remote branch. |
| Pull changes from the specified remote branch. |
| Create a new branch. |
| Switch to an existing branch. |
| Merge the specified branch into the current branch. |
| Delete a local branch. |
| Delete a remote branch. |
Make and push changes
.
Command | Description |
---|---|
| Create and switch to a new branch called "my-feature". |
| Commit changes with a message describing the new feature. |
| Push changes to the current branch on the remote repository. |
| Push the "my-feature" branch to the remote and set the upstream tracking. |
Updating a branch
git checkout
Command | Description |
---|---|
| Fetch updates from the remote repository without merging. |
| Switch to the specified branch. |
| Merge changes from the main branch into the current branch. |
| Rebase the current branch on top of the main branch. |
| Stage the resolved file after fixing any conflicts. |
If Merging | If Merging |
| Continue the merge process after resolving conflicts. |
Rebase | Rebase |
| Continue the rebase process after resolving conflicts. |
| Push changes to the specified branch on the remote repository. |
| Force push changes to the branch while ensuring safety against overwriting. |
git switch
Command | Description |
---|---|
| Fetch updates from the remote repository without merging. |
| Switch to the specified branch. |
| Merge changes from the main branch into the current branch. |
| Rebase the current branch on top of the main branch. |
| Stage the resolved file after fixing any conflicts. |
| Continue the merge process after resolving conflicts. |
| Continue the rebase process after resolving conflicts. |
| Force push changes to the branch while ensuring safety against overwriting. |
git fetch
git switch your-branch-name
git merge origin/main # or git rebase origin/main
# Resolve conflicts if needed
git add resolved-file
# if merging
git merge --continue
# if rebasing
git rebase --continue
git push origin your-branch-name --force-with-lease # if rebasing
Resolving conflicts
git checkout
git status
# Open and edit conflicted files
git add <file>
git commit
# If rebasing, continue with
git rebase --continue
git push
git switch
git switch <branch-name>
git merge <branch-to-merge>
git status
# Resolve conflicts in files
git add <file>
git commit
git push