Notes
Configuring Git Global Variables
git config --global user.name "Name" git config —global user.email “email@email.com” git config —global core.editor “code —wait” git config —global core.autocrlf “input”“
- To edit global variables:
git config --global -e
Git Status Codes
- U - Untracked →
?? - A - Added or staged
- M - Modified
- C - Committed
Common Git Commands
-
View commit history
git log --onelinegit log —oneline —graph“ -
Ignore files (prevent tracking)
- Add file name to
.gitignore - Example:
.gitignore → file.txt
- Add file name to
-
Revert to a previous commit
git reset --hard HEAD~numberOfCommitsToGoBack -
Check file status
git status -s -
Create a branch
git branch branchName -
Create and switch to a new branch
git switch -C branchName -
Switch between branches
git switch branchName -
Merge branches (must be on main branch)
git merge branchName -
Delete a branch
git branch -d branchName -
Stashing changes
git stashgit stash apply→ Apply stashed changesgit stash clear→ Clear stash memory -
Clone a repository
git clone URL -
Push changes to remote
git push -u origin branchName -
Fetch updates from remote
git fetch -
Pull updates from remote
git pull
Tips
- While pushing if got error:
error: failed to push some refs to '[https://github.com/Newbieprogram22/CppPrograms-DSA.git](https://github.com/Newbieprogram22/CppPrograms-DSA.git)'then :
git pull --rebase origin main
git push origin main