Creating a repository

git init

Getting a copy of a code from a remote repository

git clone  

Updating your repository and working copy

git pull

Adding a file to git

git add 
git commit -m "log message"

Sending your local repository changes to the remote repository

git push 

Creating a branch

git branch branch-name

Switching to existing branch

git switch branch-name

list all branches

git branch -al

Send local branch to the remote repository

git push -u origin branch-name

Delete a local branch

git branch -d branch-name

Rename a local branch

git branch -m old-branch-name> new-branch-name

Tag a commit

git tag -m tag-name

Push tag to remote repository

git push origin tag-name

List all tags

git tag -l 

Undo last commit

git  reset --hard HEAD^

Undo last commit while keeping the local modifications

git  reset --soft HEAD^

Get list of commits

git log 

Get status of current working copy

git status

Clean repository by removing untracked files and empty directories

git clean -df

Discard local modicication that have not been commited

git checkout -- . 

Undo specific commit modifications

git revert git-id

Stash modifications without commit

Warning, only saved fields already in the repository. Not untracked

git stash save "message"

List stashes

git stash list

Apply Stash

git stash apply stash@{stash-id>}

Clear stash ( Last in , first out order )

git stash drop

Like this post? Share on: TwitterFacebookEmail


Gabriel Staffelbach is a research scientist focused on new developments in HPC.

Published

Category

Tutorials

Tags

Stay in Touch