User Tools

Site Tools


programming:git:learning_git

Play with Git

Using git in command line

Git locally

First of all, we will check that Git is correctly installed.

git --version

The output should be something like :

git version 2.13.1

Now let's create our first git project !

cd /tmp
mkdir myproject
cd myproject
git init

Your first Git repository has just been created ! Now, let's add some files to the repository

If you want to learn more about git commands, check the git documentation

Create a file with some text:

echo "Hello world" >> toto.txt
ls
git status

We can see that git is aware of our file but has not added it to our repository

git add toto.txt
git status

Your work is now ready to be committed to the repository you are working on so you can work in it from anywhere (in our case, we made it locally so it is only accessible from this computer) and follow each modification that had been made to your files. In case of error or mistake, you will be able at any time to recover your last version.

Lets add some more files first !

mkdir dir1
echo "Writing some text on dir1" >> ./dir1/project.txt
mkdir dir2
echo "Another directory, another text" >> ./dir2/testing.txt
tree
git status

With the tree command you can see the files that you have created. It should look like this:

.
├── dir1
│   └── project.txt
├── dir2
│   └── testing.txt
└── toto.txt

2 directories, 3 files

You can see with git status the work that is ready to be commited and the work that is not yet in your repository. To add it all to the repository :

git add .
git status

Now, all your files are ready to be commited. To do that :

git commit -m "Adding files"
git status

Congratulations, you have added your first files to your first repository ! 8-)

For more detailed explanations and exercises, you can do the full tutorial

Sandbox

Now, let's have some fun on a real server.

cd /tmp
mkdir project2
ssh-keygen -t rsa -b 2048
scp .ssh/id_rsa.pub git.bolay.co
git clone git@git.bolay.co:sandbox
ls
cd sandbox

You can now try it by yourself modifying, adding, deleting files. Do whatever you want !

Now that you are on a server, you will need to execute:

git push

after the commit to publish the commits.

You can take a look at what is happening graphically with the command

gitx

When you want to continue working on a repository, you will need to execute

git pull

to load the last version of it.

Reference : Git Getting Started

programming/git/learning_git.txt · Last modified: 2022/11/30 12:52 by ateixeira