Skip to content

Git most used cmds

Git main commands

Configure Git (with GitHub)

Connect to Github with a SSH key (Hello-There)

Init project

git clone git@github.com:nicgen/forum.git
git fetch --all

git fetch is a command that retrieves updates from a remote repository but does not merge them with your local branch. It’s like downloading the latest changes without applying them directly to your working directory. The command fetches all the references (branches, tags, etc.) from the remote, allowing you to review or integrate those updates manually when you’re ready.

git branch --all
git switch <branchname>

Working with branches

Create a branch

git checkout -b "<branchname>"

for the first time you must set the new upstream branch:

git push -u origin front/layout-add-login-register

-u is an alias of --set-upstream

Delete a branch

It's a good idea to delete a branch in Git after you've merged it into another branch, such as the main or dev branch. This is because the changes from the deleted branch are still preserved in the branch that it was merged into, so you don't lose any history or changes. And it keeps your repository organized and clutter-free. If you have many branches that are no longer needed, it can be difficult to find the branches that are still relevant.

# delete the remote branch (once you're sure that the branch is pushed in the remote )
git push -d <remote_name> <branchname>
# delete your local branch
git branch -d <branchname>

Update the list of the remote repositories

git fetch --prune

Naming conventions

Branch Names

  • Use descriptive and concise names for branches.
  • Use lowercase letters and numbers.
  • Avoid using special characters, except for hyphens (-) and underscores (_).
  • Use a consistent naming convention throughout the repository.

Examples:

  • feature/new-login-system
  • fix/bug-123
  • release/v1.2.3

Commit Messages

  • Use the imperative mood (e.g., "Fix bug" instead of "Fixed bug").
  • Keep the first line short (less than 50 characters).
  • Use a blank line to separate the summary from the body.
  • Use bullet points or paragraphs to explain the changes.

Examples:

  • Fix bug in login system
  • Add new feature to dashboard
  • Improve performance of database queries

Important commands

Retrieve

To retrieve the remote listing, changes, branches (without merging)

Commit

Push

Conflicts

Tools:


Best practices

Here are the detailed recommendations with source links, especially for working with GitHub:

Best Practices:

  1. Create a clear and concise commit message:

    • Use the imperative mood (e.g., "Fix bug" instead of "Fixed bug").
    • Keep the first line short (less than 50 characters).
    • Use a blank line to separate the summary from the body.
    • Use bullet points or paragraphs to explain the changes.
    • Source: GitHub documentation - Commit messages
  2. Use branches:

  3. Use pull requests:

  4. Regularly pull and merge:

  5. Use GitHub Actions:

  6. Keep commits small:

  7. Use descriptive branch names:

  8. Avoid committing unnecessary files:

Working Correctly in a Group:

  1. Communicate with your team:

  2. Use a consistent workflow:

  3. Review each other's code:

  4. Use GitHub Teams: