- Status in current branch:
git status
- Show all remotes:
git remote
- Check to see if you are up to date with the current branch:
git fetch
- Switch to a different branch within current remote:
git checkout branch_name
(Example:git checkout master
or gitcheckout zubaer
) - Switch to a different branch within a different remote:
git branch -u remote_name/branch_name
(Example:git branch -u production/master
orgit branch -u origin/master
). It is important to provide-u
. Otherwise, it will try to create a new Branch. - Create a new Branch:
git branch branch_name
(Example:git branch zubaer
). - Show commit history:
git log
- Git add all:
git add .
- Git commit:
git commit -m 'Commit text'
- Push to a branch:
git push remote_name branch_name
(Example:git push production master
orgit push origin master
) - Git use mergetool to resolve conflictions:
git mergetool
- Git force push to a branch:
git push remote_name branch_name --force
(Example:git push origin master --force
) - Hard reset to a previous commit:
git reset --hard commit_reference_id
(Example:git reset --hard 0d1d7fc32
). It is important to remember that you will loose all works after that commit by this. - Reset to aprevious commit keeping present works: i)
git stash
ii)git reset --hard 0d1d7fc32
iii)git stash pop
. So What is happening here are as follows: i) You are saving or stashing away you current works ii) You are going back to an old commit and making some edits iii) You are merging the saved works (i) with the patches/edits you have made on (ii). This will arise conflicts and you can merge them with git mergetool command. - Git show url of a Remote:
git remote show remote_name
(Example:git remote show production
orgit remote show origin
) - Git show all remote refs or remote branchs:
git show-ref
- Git remove a file or folder without deleting it locally:
git rm file_name --cached
. For a folder:git rm -rf folder_name --cached
- Git add a Remote:
git remote add remote_name remote_url
(Example:git remote add production ssh://[email protected]/var/repo/site.git
) - Git change url of a remote:
git remote set-url remote_name git://new.url.here
(Example:git remote set-url production ssh://[email protected]/var/repo/site.git
) - Git see ref logs or activities:
git reflog
- Delete a remote:
git remote remove remote_name
(Example:git remote remove staging
). - Git show all configs:
git config --list
- Git set a config Globally:
git config --global user.email "[email protected]"
- Git set a config specifically for a project:
git config user.email "[email protected]"
- Git show all remotes with urls:
git remote -v
Last active
December 25, 2018 09:12
-
-
Save zubaer-ahammed/873f8b39dec0f51c6cc8daa3340dc889 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment