-
Create Repository
git init git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY git push -u REMOTE-NAME BRANCH-NAME
-
Create new BRANCH locally
git checkout -b NEW-BRANCH-NAME
To push the locally created new branch to remote
git push --set-upstream origin NEW-BRANCH-NAME
-
List local branches
git branch
-
Switch branch
git checkout branch-name
-
Stash/Un-Stash files
One of the ways to resolve the checkout error is to stash the changes. This is usually done temporarily to save the work you have done so far in the current branch — if you are not ready to commit these changes.
git stash
To recover or undo the stashed changes, we can come back to the branch where we stashed the changes and pop them.
git stash pop
-
Check branch status
git status
-
Rename local branch
git branch -m OLD-BRANCH-NAME NEW-BRANCH-NAME
-
Rename remote branch
git push origin :OLD-BRANCH-NAME NEW-BRANCH-NAME
-
Synchronise branch changes
# To add all changes git add . # To add a specific file git add FILE-PATH git commit -m "COMMIT-MESSAGE" git add FILE-PATH git commit --amend -m "CHANGE-COMMIT-MESSAGE"
-
Clone repository
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
-
Checking commit log
git log
-
Reset to the last commit
git reset -hard origin/BRANCH-NAME
-
Merge local repository with the remote repository
# Fetch remote from github git fetch REMOTE-NAME # Merge remote branch with local branch git merge REMOTE-NAME/BRANCH-NAME git pull REMOTE-NAME BRANCH-NAME
-
Move a commit from one branch to another
git cherry-pick COMMIT-HASH
-
Remove untracked files & directories
# To remove untracked files git clean -f # TO remove untracked directories git clean -fd
-
Delete a branch on a local repository
git branch -d BRANCH-NAME # To forcefully delete a local branch. Be careful git branch -D BRANCH-NAME
-
Delete a branch on a remote repository
git push REMOTE-NAME --delete BRANCH-NAME
-
Ignore Git permission changes
git config core.fileMode false
-
Fix .gitignore
touch .gitignore# To untrack the unnecessary tracked files in your gitignore which removes everything from its index. Specific filenames can also be used instead of dot(.).
git rm -r --cached .
git add .
git commit -m "gitignore fixed untracked files"