User Tools

Site Tools


cs:git
Return to Home page

Git

Useful resources for git subversioning system

Example of git commands (client)

  1. git init: in a directory create a new repository
  2. git status: check the current status of the repository
  3. git 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
  4. git commit -m “message”: files are committed to the repository, providing a message that describes the commit operation
  5. git log: print log of commit
  6. git remote add origin <url>: Create a remote repository with location <url>. origin is the name of the remote repository
  7. git 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
  8. git pull origin master: pull the change from the remote repository origin to the local repository master
  9. git diff HEAD: differences between the master repository and our last commit. HEAD is the last commit
  10. git diff –staged: differences between committed files and staged files (i.e., the one added to the repository or modified, but not jet committed)
  11. git reset <filename>: remove filename from the repository
  12. git checkout – octocat.txt: takes the file octocat.txt from the remote repository
  13. git branch foo: create a branch (a copy of the repository) with name foo
  14. git branch: list the branches (master and foo)
  15. git checkout foo: switches to branch foo
  16. 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”
  17. To merge foo branch with master
    • git checkout master to change the repository
    • git merge foo: does the merge
    • git branch -d foo: deletes branch foo
  18. git push: remember to push changes to the remote repository

Guide for using git: https://try.github.io/levels/1/challenges/1

Setup git server

On the client

  1. ssh git@apinda.polito.it “git init –bare /home/git/abc.git”: creates the new remote repository
  2. git clone git@apinda.polito.it:/home/git/abc.git: copy the new repository locally
  3. git add <files>
  4. git commit -m “message”
  5. git push origin master: Le altre volte basta fare git push

Double commit and 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

Resources


If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/git?do=
/web/htdocs/www.skenz.it/home/data/pages/cs/git.txt · Last modified: 2020/11/26 23:18 (external edit)

Privacy Policy