GIT command line syntax for basic operations

From Luniwiki
Jump to: navigation, search

Here are the commands to:

  1. Clone (Checkout in SVN) a repository
  2. Create a new file
  3. Update the file
  4. Remove the file

Clone repository

git clone https://dsimao@git.luniel.com/git/log2mysql.git log2mysql
Cloning into 'log2mysql'...
Password for 'https://dsimao@git.luniel.com':
...
Resolving deltas: 100% (138103/138103), done.
Checking connectivity... done.
Checking out files: 100% (29505/29505), done.

This command will clone the repository in the folder log2mysql

cd log2mysql
git config --global user.name "Daniel Simao"
git config --global user.email daniel.simao@luniel.com
git config --global push.default simple
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

Create a new file

mkdir test
git add test
echo "hello" > test/testfile
git add test/testfile

The file is created in the local file system

git commit -m "Adding a testfile"
[master 5d3a52e] Adding a testfile
1 file changed, 1 insertion(+)
create mode 100644 test/testfile

Commit of the file creation

git push
Password for 'https://dsimao@git.luniel.com':
Counting objects: 2, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 274 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
To https://dsimao@git.luniel.com/git/log2mysql.git
  5d3a52e..07008ff  master -> master

Push the file creation to the central repository.

Update a file

echo "adding more stuff on the file" >> test/testfile

File is modified.

git commit -am "test file updated"
[master 01bc2ac] test file updated
1 file changed, 1 insertion(+)

Commit the modification (take care to add the modifier -a)

git push
Password for 'https://dsimao@git.luniel.com':
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 352 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
To https://dsimao@git.luniel.com/git/log2mysql.git
  07008ff..01bc2ac  master -> master

Push of the update

Delete a file and folder

git rm -r test

Deletion of folder and file (modifier -r do it recursively)

git commit -m "Removing test folder"
[master b9444c2] Removing test2 folder
1 file changed, 2 deletions(-)
delete mode 100644 test2/testfile
Commit of deletion
git push
Password for 'https://dsimao@git.luniel.com':
Counting objects: 2, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 243 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
To https://dsimao@git.luniel.com/git/log2mysql.git
  01bc2ac..b9444c2  master -> master

Push of deletion

References

Daniel Simao (talk)