../

Git CLI Commands

1. Initializing Git

git init .

2. Staging and Unstaging Files

git add .
git reset .

3. Committing

git commit -m "commit message" "commit description(optional)"

4. Setting Remote Repositories

git remote add origin https://github.com/somewhere/something.git
git remote -v
git push -u origin master

OR

git push --set-upstream origin branch_name

5. Git Branches

git branch
git checkout -b branch_name
git checkout - (moves to the previous branch)
git branch -d branch_name

6. Merging

git merge branch_name 

7. Squashing

Merge all the commits in a branch as a single commit

git merge branch_name --squash

8. Pulling

git pull origin master

9. Combining add & commit

git commit -am "commit message here"

10. Git Aliases

git config --global alias.command_name "command -am"

AND

git config --global alias.command !better-command.sh : execute a script

11. Amend

git commit --amend --no-edit
git commit --amend -m "new commit msg"

12. Force Push

overwrite history on remote

git push origin master --force

13. Revert

Undo a commit with a new commit

git revert undoed_better_commit

14. Stash

will remove the newly made changes from the current working directory and save them for later use without committing them to the repository

git stash --all
git stash pop
git stash save stashing_name
git stash list
git stash apply index_number_from_the_stashed_list

15. Renaming the Master Branch

git branch -M mucho

16. Pretty Git Logs

git log --graph --oneline --decorate

17. Diffing

git diff branch_name/change_name

18. Patching

selecting only a few changes manually in a file without staging the whole file

git add -p change_name

19. Increasing the buffer size

git config --global http.postBuffer 1048576000

Tags: /git/ /vcs/ /commands/