Outils pour utilisateurs

Outils du site


issue85:c_c

Ceci est une ancienne révision du document !


Last month I began introducing the various concepts and terminology used by Git. This month we'll be taking it a step further, and running through a series of examples on actually using Git (in combination with GitHub; creating a custom Git server falls outside of the scope of this article). I will be assuming you either have a free account with GitHub, or else that you have found someone's repository you'd like to clone. For anyone who is interested, I created a public repository for this article, which can be found here: https://github.com/lswest/Command-Conquer-Examples. Note: If you don't have a GitHub account, and are using someone's repository, you will not necessarily be able to push to them. You can create your own copy of the repository by forking it (requires an account as well).

Le mois dernier, j'ai commencé à introduire les différents concepts et la terminologie utilisés par Git. Ce mois-ci, nous allons aller un peu plus loin, et parcourir une série d'exemples sur l'usage réel de Git (en combinaison avec GitHub; la création d'un serveur Git personnalisé est hors-sujet de cet article). Je supposerai que vous avez soit un compte gratuit sur GitHub, ou alors que vous avez trouvé le dépôt de quelqu'un que vous aimeriez dupliquer. Pour ceux qui sont intéressés, j'ai créé un dépôt public pour cet article, qui peut être trouvé ici: https://github.com/lswest/Command-Conquer-Examples.

Remarque: Si vous n'avez pas de compte GitHub, et que vous utilisez le dépôt de quelqu'un, vous ne serez pas nécessairement en mesure de téléverser vers lui. Vous pouvez créer votre propre copie du dépôt par bifurcation (ça nécessite aussi un compte).

Step One: Create a Repository If you would prefer to use an existing repository (or not create a GitHub account), skip this step. At the very top of the screen when logged into GitHub, you'll see your username, and next to that a plus sign. Click the plus to create a new repository. You can enter the following information: Required: • Repository Name • Owner • Public/Private (Private is available to only paying members) Optional: • Description of the repository • Initialize with a README • .gitignore settings • Choosing a license for the repository.

Première étape: créer un dépôt

Si vous préférez utiliser un dépôt existant (ou ne pas créer un compte GitHub), ignorez cette étape.

Tout en haut de l'écran lorsque vous êtes connecté à GitHub, vous verrez votre nom d'utilisateur, et à côté un signe plus. Cliquez sur le signe plus pour créer un nouveau dépôt. Vous pouvez entrer les informations suivantes:

Requis: • Nom du dépôt • Propriétaire • Public / Privé (privé est disponible seulement pour les membres payants)

Facultatif: • Description du dépôt • Initialisation avec un Lisez-moi. • Paramètrage de .gitignore • Choix d'une licence pour le dépôt.

Step Two: Clone the Git Repository There are some GUI Tools for Linux, but for the sake of this article, I will refer to only the actual terminal commands: • Open a terminal. • cd to any subfolder where you want the repository located. • Enter: git clone https://github.com/lswest/Command-Conquer-Examples.git • Depending on the size of the repository, it may take a moment. Once you're back at your prompt, you have successfully cloned it. You may now want to cd into the repository folder (in my case: cd Command-Conquer-Examples).

Step Three: Making Changes For the sake of this example, I'll be editing the README.md file. Naturally, the procedure is the same with any edit: • Open the file in your favourite editor. • Make your changes. • Once the file is saved, you then need the following command: git add <file> Note: if you want to add all files, simply use a period instead of the name of the file.

Step Four: Commit Once you've added the file you want, and are ready to commit them into the next update to your repository, you can run the following command: git commit If you run the command like this without any arguments or parameters, it will prompt you to enter a message for the commit before finishing. A couple useful options are: • -a: Automatically adds any changes files (but ignores newly added/removed files). • -m <msg>: Uses the message supplied for the commit message – i.e. -m “First commit – edited README.md”.

Step Five: Push Now that you've created a commit listing all the changes you want to take over onto the remote repository, you're ready to synchronize them. In Git this is called a push. The format of the command is: git push <local> <remote> By default when using Github, the local will be origin, and the remote will be master. If you're working on a more complicated repository, you'll need to check the exact branch names. In this example, the command will most likely be: git push origin master If you haven't configured git to store your username and password for Github, you'll be prompted for those now. As is the custom in Linux, the prompt for the password will not display any characters at all, but will indeed register your keystrokes.

Step Six: Checking the Remote Once you've pushed your changes, you'll see the newest commit listed on the repository page. The commit message appears only on files that were affected by it. This helps to keep track of which files aren't being changed frequently. Further Possibilities Possibility One: Adding a New File In step 3, we discussed how to edit files that already exist in the repository. First create a new file using whatever method you need, and then add it to a commit with git add <file>. Once you've added it, follow steps 4-5. Possibility Two: Removing a File If you want to remove a file from the repository, simply deleting it from the filesystem isn't enough. You'd need to use the git command, git rm. Once a file is deleted with this (i.e. git rm “Adding a file.txt”), you can then commit the change and push it to the repository, by following the steps 4-5. Hopefully this article has helped to shed some light on using GitHub and Git repositories. If you have any difficulties, or want information on a specific scenario, feel free to email me with your questions. As always, I can be reached at lswest34+fcm@gmail.com. For anyone who is interested in hosting their own git servers, I would be happy to write an article on this topic too (if there is sufficient interest).

issue85/c_c.1417111065.txt.gz · Dernière modification : 2014/11/27 18:57 de frangi