Some git commands to remember
by Jerad Rutnam -
Here is a list of Git commands that you should remember that will use more commonly.
Git Clone
git clone <repo> # Clone repo
git status # Check which branch you are working onGit Create & Push Branch
git checkout -b <branch_name> # Create local branch
git push <remote_name> <branch_name> # Push branch to git, <remote-name> = "origin"
git add --all # Add changes to clone
git commit -m "string message" # Commit changesGit Rename Branch
git branch -m my-hot-feature feature-15 # Rename branch localy
git remote -v # Get remote name
git push origin :<old_branch_name> # Delete the remote branch with the old name
git push origin <new_branch_name> # Re-create the remote branch with the new nameGit Delete Branch
git branch -d <branch_name> # Delete branch localy, -D for force delete
git push origin --delete <branch_name> # Delete remote branchGit Pull
git checkout master # Change branch to master
git pull # Pull the changes
git checkout <branch_name> # Change branchGit Push
git checkout master # Change branch to master
git pull # Pull the changes
git checkout <branch_name> # Change branch
git add --all # Add changes to staging
git commit -m "string message" # Commit changes to local
git push # Push commits to repoConfiguring a Git remote for a fork - Set UPSTREAM
git remote -v # Checking remote repos
git remote add upstream <https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git> # Adding upstream [original repo] to git remote
git remote -v # Checking remote repos again to see whether its updatedChange Git remote url - update orgin
git remote -v # Checking remote repos
git remote set-url <https://github.com/YOU/FORKED_REPOSITORY.git> # Change orign [fork repo] url
git remote -v # Checking remote repos again to see whether its updatedGit fetch from Upstream
git fetch upstream # Git fetch from upstream
git checkout master # Change to local 'master' banrch
git merge upstream/master # Merge local with fetched upstream changesGit force merge local from branch
git fetch --all # Git fetch from branch
git reset --hard upstream/master # Git force reset local
git push origin master # Git push to repository master branchGit force pull
git fetch origin master # Git fetch master
git reset --hard FETCH_HEAD # Setting head to the fetched
git clean -df # Force clean to headGit force revet to a previous commit
git reset --hard <revision_id_of_last_known_good_commit> # Reset back to a last known good commit
git push --force # Force update repoGit update & merge local repo with a specific PR
git fetch upstream pull/<pr>/headGit create a branch with specific PR
git fetch upstream pull/<pr>/head:<pr>
git checkout <pr>Git rebase pull (To avoid merge commits)
git rebase upstream/master