Git command cheatsheet

Spread the love

Configuring Git

git config –global user.name “Your Name”

git config –global user.email “[email protected]

Basic Git Commands

git status

git add <file_name>

git add .

git commit -m “Your commit message here”

Branching and Merging

git branch <branch_name>

git checkout <branch_name>

git switch <branch_name>

git checkout -b <branch_name>

git merge <branch_name>

git

Remote Repositories (GitHub)

git remote add origin <repository_url>

git push -u origin <branch_name>

git pull origin <branch_name>

Viewing History and Diffs

git log

git show <commit_hash>

git diff

git diff HEAD

1 6S1nFUgi payS5Lxhtv05A

Undoing Changes

git checkout — <file_name>

git reset HEAD~1

Gitignore

# Remove all text files

*.txt

# Remove a folder

/foldername

Creating and Cloning Repositories

git init

git clone <repository_url>

download

GitHub Workflow

  1. Fork the repository on GitHub.
  2. Clone your fork to your local machine.
  3. Add the original repository as a remote.
  4. Create a new branch for your changes.
  5. Make and commit changes in the new branch.
  6. Push the changes to your fork.
  7. Create a pull request on the original repository.
  8. Discuss and review changes with collaborators.
  9. Merge the pull request into the main branch.

Be the first to comment

Leave a Reply

Your email address will not be published.


*