0% found this document useful (0 votes)
29 views2 pages

Essential Git Commands and Troubleshooting

The document provides a comprehensive overview of Git commands for managing repositories, including adding, committing, and pushing changes, as well as branching and merging. It also addresses common errors encountered during Git operations and offers solutions for unstaging and resetting commits. Additionally, it includes instructions for creating new branches and handling pull requests.

Uploaded by

findyandx
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Essential Git Commands and Troubleshooting

The document provides a comprehensive overview of Git commands for managing repositories, including adding, committing, and pushing changes, as well as branching and merging. It also addresses common errors encountered during Git operations and offers solutions for unstaging and resetting commits. Additionally, it includes instructions for creating new branches and handling pull requests.

Uploaded by

findyandx
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Gid add: track changes

Git commit: commit changes


Git push: git push origin main
Git status
Ssh keys git remov

New git repository:


Git init
Git add
For modified files: Git add and commit: git commit -am <message>

Git commit
Git push: get error(create connection)
Git remote add origin <git repository url>: add reference
Git remote -v: shows remote rep connect
Git push –u origin main
upstream(default location)

Git branching
Master branch(default)
Feature branch
git branch
Create new branch: git checkout -b <name of branch>
Change branch: git chechout <branch name>
Compare two versions of code: git diff <branch name>
Merge changes: git merge <branch name to merge to>
Get a message of no upstream branch
Solution: git push -u origin <branch name>

Pull request

Undoing commits
Unstaging previous commits: git reset/ <name of file to ustage>
Unstaging pushed commit: git reset HEAD~1(pointer to last commit,~1, last commit)
To view all commits: git log
To unstage to a specific commit: git reset <#commit>
To completely remove commits(not just unstaging): git reset –hard <#commit>

Fork repos

Common errors:
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to
'[Link]
hint: Updates were rejected because the tip of your current branch is
behind
git pull origin main
git pull origin main.
git pull origin main
● branch main -> FETCH_HEAD
fatal: refusing to merge unrelated histories
git merge --allow-unrelated-histories origin/main
git push origin main

You might also like