Hello dears,
Here is a list of common Git commands that I use.
If you are wanting to learn Git I recommend this tutorial from Atlassian https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud
Starting with Git
Mostly basic command, start of everything 🙂
git init
You can also add a remote repository
git remote add origin https://github.com/USER/REPOSITORY.git
Or you can just start by cloning other repository
git clone https://your.repository.url
Git Daily usage commands
Listing all branches including in server
git branch -a
Create new branch
git branch NameOfYourNewBranch
git checkout -b NameOfYourNewBranch
Git shows status of everything in your repository
git status
Adding files to stage
git add file_1 file2
You can also add everything
git add .
Downloading updates from your colleagues
git pull
Creating a new commit
git commit -m 'message'
Publishing/Saving your code
git push origin YourBranch
Changing your branch to another
git checkout WantingToMoveToAnotherBranchHere
You can merge changes to your branch doing this
git checkout *1-your-branch
git merge *2-future-plans
*1- name of branch that will receive updates
*2- code that will be imported
If you’re not working with pull requests, when you merge your branch, you also can delete your future-plans branch because you won’t use it anymore. However, if you’re using pull request, only remove your branch when the pull request is accepted.
git branch -D YourBranchName
Git Useful commands
Show what was changed in some file
git diff YourFileName
You can also compare changes between different branches
git diff main new_branch ./diff_test.txt
Show last updated files in your repository from log. You can change the number of commits
git log -3 --name-status
Reset / Discard everything from your local (BE CAREFUL)
git reset --hard && git clean -fd
Discard file changes from your stage
git checkout -- [filename]
Unstaging files, based on your repository
git reset --hard HEAD file or .
Git clean interactively
git clean -i