Useful resources for git subversioning system
git init
: in a directory create a new repositorygit status
: check the current status of the repositorygit add <file_list>
: add <file_list> to the repository (files are added in the staging area, .git
hidden folder)git add '*.txt
': add all .txt
file to the repository (staging area) in a while git commit -m “message”
: files are committed to the repository, providing a message that describes the commit operationgit log
: print log of commitgit remote add origin <url>
: Create a remote repository with location <url>. origin
is the name of the remote repositorygit push -u origin master
: push the content of the local repository master to the remote repository origin. The -u
option tells git to save origin
and master
name. As a consequence, the next call should be git push
git pull origin master
: pull the change from the remote repository origin to the local repository mastergit diff HEAD
: differences between the master repository and our last commit
. HEAD
is the last commit
git diff –staged
: differences between committed files and staged files (i.e., the one added to the repository or modified, but not jet committed)git reset <filename>
: remove filename from the repositorygit checkout – octocat.txt
: takes the file octocat.txt
from the remote repositorygit branch foo
: create a branch (a copy of the repository) with name foo
git branch
: list the branches (master and foo)git checkout foo
: switches to branch foo
git rm '*.txt
': remove all file with extension .txt
from the branch foo
. To remove a directory: git rm -r <dir_name>
(changes can be committed with git commit -m “message”
foo
branch with master
git checkout master
to change the repositorygit merge foo
: does the mergegit branch -d foo
: deletes branch foo
git push
: remember to push changes to the remote repositoryGuide for using git: https://try.github.io/levels/1/challenges/1
ssh git@apinda.polito.it “git init –bare /home/git/abc.git”
: creates the new remote repositorygit clone git@apinda.polito.it:/home/git/abc.git
: copy the new repository locallygit add <files>
git commit -m “message”
git push origin master
: Le altre volte basta fare git push
Sometimes, after a double commit
followed by a push
, git returns an error. A possible way to resolve the error is running the following there commands:
git stash git pull git stash pop