Skip to content

Covers nearly all Git requirements in just 8 minutes

If you're interested in exploring Medium, think about getting a membership to aid me and various other writers. It's only a small monthly fee of $5, the contribution significantly helps us, and you'll have access to a wealth of engaging stories on Medium. Questions about the specifics? Let me...

Rapidly master 99% of Git functions within just 8 minutes
Rapidly master 99% of Git functions within just 8 minutes

Covers nearly all Git requirements in just 8 minutes

Navigating Git effectively is essential for collaborative coding projects. Here's a comprehensive guide to help you push your work to GitHub or GitLab efficiently, avoiding common pitfalls.

Synchronize Local and Remote Repositories

  1. Use to download changes from the remote repository without merging them immediately. This allows you to review updates first.
  2. Use to compare differences between your local and remote branches.
  3. Use (replace with the relevant branch) to integrate remote updates into your local branch. Alternatively, use to fetch and merge in one step, or to keep a linear history by applying your changes on top of the updated remote branch.

Create a Branch

Before starting new work, create a feature branch with to isolate your changes and avoid affecting the main branch directly.

Commit Work Locally

  1. Stage changes with or for specific files with .
  2. Commit staged changes with a meaningful message using .

Push Changes to Remote Repository

  1. Link your local repository to the remote (usually named ) if not done: (HTTPS or SSH link).
  2. Push your branch to the remote repository with: .

Create a Pull Request (GitHub) or Merge Request (GitLab)

  1. Navigate to the repository on GitHub or GitLab.
  2. You will usually see an option to "Compare & Pull Request" or "Create Merge Request" for the pushed branch.
  3. Fill in a descriptive title and description explaining your changes and why they’re needed.
  4. Submit the request for review.

Review and Iterate

  • Collaborate with maintainers or team members, responding to feedback and making changes if requested.
  • Resolve any merge conflicts that arise.
  • After approval, the pull or merge request is merged into the main codebase.

Following this workflow ensures your local and remote repositories stay synchronized, your work is properly branched and documented through commits, and contributions are integrated via reviews for quality control. Using commands like , , and creating branches before committing helps maintain a clean, efficient Git history and collaborative environment.

For more information about Git, consider reading the "Git Pocket Guide". If you face conflicts during a rebase, follow the steps to resolve the conflict, commit the changes, and force (with lease) push the rebase. If someone updated your branch while you were doing the rebase, you will have to restart all the steps of the rebase and pull from your branch, the remote branch.

Remember, a commit message should be assigned, describing the commit's purpose. After synchronizing, using command with the copied link will connect the local repository with the remote repository. This command needs to be written every time a new branch is created and pushed. A push is a delivery of local work to the remote repository, containing one or several commits.

If an error occurs because of uncommitted files, either commit them or restore them to their previous state. After committing, changes need to be added using or by specifying individual files. The merge button might be grey instead of green, indicating a conflict. This happens when someone made changes on the same file as you and merged a modified version that you have not seen.

Creating a branch is recommended for new developments to avoid disturbing the main branch (master on GitLab, main on GitHub). A hack to avoid writing the command every time is modifying an internal git file to automatically create and synchronize the local branch on the remote repository. The status of the changes can be checked using . To create a branch, one can use the command followed by .

If a banner message proposes to open a merge request, click on it and proceed to submit a merge request with a title, descriptions, and reviewers. If you encounter any issues or have further questions, refer to the resources available online or reach out to your team for assistance. Happy coding!

  1. To maintain a clean Git history and improve collaboration, use commands such as , , , , , and to manage local and remote repositories efficiently.
  2. Using Git technology, like creating and working on separate branches before committing, ensures that new developments do not interfere with the main codebase, making it easier for collaborative coding projects.

Read also:

    Latest