Useful git commands for everyday use!

git command

- Init git project:

git init 

Clone repo from link

git clone [link]

- View remote

git remote

- Save username, password

git config credential.helper store

- Update code and write to local file 

git pull

- Pull new code but not write to file.

git fetch

- Switch branch

git fetch origin         <----this will fetch the branch
git checkout branch_name <--- Switching the branch

- Rename branch:

Rename your local branch.

If you are on the branch you want to rename:

git branch -m new-name

 

If you are on a different branch:

git branch -m old-name new-name

 

Delete the old-name remote branch and push the new-name local branch.

git push origin :old-name new-name

 

Reset the upstream branch for the new-name local branch. Switch to the branch and then:

git push origin -u new-name

- Update submodules


git pull --recurse-submodules

or


git submodule update --remote --recursive

 

git stash
git stash pop
git checkout [file/folder]
git checkout -f branch
git branch