Git cheat sheet

Earlier I've been using git as a file storage solution for myself rather than for versioning. Now I'm working in a team, so I need to learn more about git. So, I sometimes need to use this cheat sheet. I'm posting it in case it helps someone else. We use Azure DevOps Repos, not GitHub, in case something differ here.

Status

git status

Status-command shows which files that have changed but have not yet been commited.

Add/Stage

git add [fil(er)]

With "add" you add files which you have altered and make them ready to be commited. You can't add a file by its filename or if you want to add all changed files by .. The wonderful thing with "add" is that you can choose which files to include in a commit.

Commit

git commit -m "ett beskrivande meddelande"

This updates the files in your repo and creates a point from which you can restore.

Push

git push

Push your files to your remote repository, for example Azure DevOps Repos or GitHub.

Pull

git pull

Downloads the latest changes from remote repository.

Clone

git clone [url]

Clones/Copies and creates a work copy of existing repository.

Branch

git branch [namn]

Creates a new branch of existing repository. When you switch between branches git will make sure that only the current branch files is in your folder.

Merge

git merge [namn]

Merges current branch with the name you choose.

Rebase

git rebase master

Updates your branch so that it's in sync with master branch. Do this often if you are many developers who commits to the same repository. Remember to do a pull before you do a rebase.

Stash

git stash

Stash saves your current changed temporary. Useful if you wuickly want to change branch and not lose your changes. Do restore stash you just run:

git stash pop