2 software and 1 website :
- Create an account of github.com in my case, it will be pierre.jean@umontpellier.com
- Download and install Git from https://git-scm.com/downloads
- Download Zip version of VScode https://code.visualstudio.com/download according your internal processor (Windows usually x64, Mac usually universal) and unzip the file somewhere you usually install program (on the desktop in my case)
If you want to train more about Git you can use this page for beginner to advanced user : https://pierrejean.wp.imt.fr/2023/09/08/oh-my-git/
F&Q
- With Git, there are several ways to do the similar thing…
- The default branch could be main but it was common to have main.
- Github is not the only website for Git: Gitlab, Sourcesup (Renater), Bitbucket, Amazon, etc. but Github is the most famous
- VScode is different from Visual Studio from Microsoft
Very simple configuration on Github Website
On the GitHub account opens by click on the top right circle icon, then choose « Settings »
Then at the bottom, choose « Developper settings » at the bottom end :
Then Personal access tokens > Tokens (classic) or just follow https://github.com/settings/tokens , then « Generate a personal access token » :
Then you can provide a name of this token, give an expiration date (not perpetual), give right at least on repo rights and press the bottom button « Generate token » :
Then you have to copy the generated token, please be sure to copy the token because there is no way to give you back this one. If you lost it, you have just to create a new one.
You have to preserve somewhere those three informations from Github:
- The email account used to create the github account
- The account name used, you can find by clicking again of the top right small circle
- The tokens key just generated
Github website provides the basic start we need on the first page you see after login creation or you can return with the Github icon or the « Dashboard » link :
At first, create a new private repository to practice call hello1 :
Then you have the quick look on commands that we will learn bellow:
Also, you need to keep the URL address like just the username of your account and the name of the repository for later as :
https://github.com/pierre-jean-dhm/hello1.git
If you need to change public/private settings or delete the repository, just click « Settings » and top bottom, you will find « Change repository visibility » and « Delete this repository« .
VScode and your folder
We will imagine, we will work into a folder on the desktop call Hello1 that could be empty of not. So create this Hello1 folder where we will work and you can see the full path into the Windows explorer address bar : C:\Users\pierre.jean\Desktop\Hello1\
Open the VScode folder and click on the code program to start it, choose « Open Folder… » and choose C:\Users\pierre.jean\Desktop\Hello1\
You can confirm, you trust the folder content (empty in my demonstration) :
Then, you can close the « welcome tab », open the terminal (Menu View > Terminal) and switch to « Source control » button on the left vertical bar.
So now into this terminal, just enter the following command but replace with the email address from the Github website :
git config user.email "pierre.jean@umontpellier.com"
You should have an error because the current folder is not setup for Git, so at first execute this command :
git init
VScode button « Initialize Repository » could also execute the same command just by pressing but there are so many terminal commands to learn instead…
You can see into the folder with « File explorer » (or Finder) there is a hidden file call .git :
So you can call back the previous command (up arrow) to configure the email you preserve from the Github settings :
git config user.email "pierre.jean@umontpellier.com"
And the account name also from the
git config user.name "pierre-jean-dhm"
NOTE :If you want to change it, just call again the same command. And if you want to « un-git » the project, just delete the .git folder.
You can add a very new useful command line (git lg) with this command, so just copy and paste into the terminal and press ENTER:
git config alias.lg "log --oneline --all --decorate --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Enter this command to use the main branch name instead of historical master branch name for all your project (so –global) :
git config --global init.defaultBranch main
But we need to rename the branc from master to main with :
git branch -m master main
Now, let’s start on a first project’s file.
NOTE: if a command ouput will not fit into the terminal area missing some place, you will see double dots:
So press SPACE key to see one more page until message END is shows then press Q key to quit.
NOTE2: if you close by mistake terminal, just open it again, Menu View >
Let’s start with versions control (Global Information Tracket)
1/ One new file, add and commit
Into the Hello1 folder, create a file equipe1.txt with menu File > New Text file
On the right, begin to enter text to remove the advice text « Select a language… », so enter :
Pierre
Save the file with equipe1.txt name :
Then we need to ask Git to follow this file equipe1.txt, inside the terminal enter :
git add equipe1.txt
We can also just click into the small + symbol to add this file « Stage Changes »:
Then create a first commit of this version of file with :
git commit -a -m "Initial version"
-a : for all file added previously
-m : to provide a message in this example « Initial version »
The « git commit » action is really to say « All those files are at the same point of development »
F&Q
- Why to use git add : because some files could be into the folder and you do not want to include them into the version control
- How to add several files and folders : with git add . or git add :/ to add everything into the current folder or everything into where you execute git init.
- How to undo git add equipe1.txt : with git reset equipe1.txt
- Why two command to add and commit : Several raisons, but I like to say: when I create a new file for a project, I add it at this moment into GIT with git add then later, I will include this file and more into the commit « package » with git commit.
- Git and folders: GIT only manage files, if there is an empty folder, GIT will not manage it, so place a README.md file into and git add :/
- Editor : You can use any editor as Notepad, UltraEdit, Matlab, etc. to create files but some editors will be updated by Git some other not, later it could be complex to close and reopen file each time to avoid troubles.
- You can use arrow up to find a previous command
- You can clear the terminal with cls or clear commands
We want to know what append into GIT so the previous command git lg will show us (or the short version git log –oneline –graph –all –decorate) :
We can display the status of our first commit with git log or git lg :
Each element is very important :
- * : symbol for the active branch actually the main branch is call « main »
- 727ce9e: short version of ID of the commit number, each commit will have a different version
- HEAD : the position of the folder content files at present, the most important element
- -> : very important symbol HEAD state is link to main state of the main branch
- main : name of the first branch of commits (It could be master also)
- Initial commit : the message of this version
The git lg command add more information, date of the commit and user name.
3/ Second version of our file
Edit the equipe1.txt file with this additional content and save it (CTRL+S):
Pierre
Gérard
Then commit this new version with the classical :
git commit -a -m "Team of 2 players"
Display the log via git lg (or git log –oneline –graph –all –decorate) :
We have 2 commits so we have two versions of our group of one file (equipe1.txt), the first version 727ce9e and the second is 939516a.
4/ Time machine
Suppose we can to go back to the first or previous version, you can either:
- go to the version 727ce9e : with git checkout 727ce9e
- go to the actual position (HEAD) minus one with : git checkout HEAD^
- go to the actual position (HEAD) minus a number (here one) with : git checkout HEAD~1 or git checkout HEAD^1
git checkout HEAD^
We see the equipe1.txt file content change to display the previous content. So we move back in time, the content of our file change to display the previous version :
We return to the last commit with git checkout main.
F&Q
- Version number of position: you should avoid to use version number all the time. There are HEAD~number, and there are branch name and tag and so much
- How to go back into the future: git checkout main or git switch main
- Detach HEAD, a HEAD is normally supposed to point on the last element of a branch, without a branch name HEAD is just a flag on the history of commits version.
- Why you should not do git checkout baf9c8d : the situation is called a detached HEAD, in fact the version control of GIT will keep main branch pointing on the baf9c8d version. So if you created a new commit version you will have the following situation :
* e04c5e7 - (HEAD) version detach of branch (3 seconds ago)
* 939516a - (main) Team of 2 players (63 minutes ago)
* 727ce9e - First commit (2 hours ago)
So the HEAD moves with the new version, but the branch name stayed on 939516a.
5/ VScode
You can use VScode to avoid most of the command, for example add a new file equipe2.txt into the folder Hello1. We don’t need to add a new file and a new commit, just a way to understand where are the buttons:
But VScode allow only to do git checkout with branch so …
6/ Branches
To avoid mix into the development, you have to think that your work will be share with someone. You should have 3 branches, your main/master branch, a develop/temporary/feature/test branch and the remote main/master branch.
First of all, where are in this situation :
* 939516a - (HEAD -> main) Team of 2 players (63 minutes ago)
* 727ce9e - First commit (2 hours ago)
One file equipe1.txt with the following content :
Pierre
Gérard
We want to simulate a different way to develop our file. So we go back to the initial commit and we create a develop branch and try to work on :
git checkout HEAD~1
git branch develop
But we have to display the situation with git lg (of git log –oneline –graph –all –decorate) :
* 939516a - (main) Team of 2 players (2 hours ago)
* 727ce9e - (HEAD, develop) First commit (4 hours ago)
There is a problem, HEAD is not linked to develop, HEAD is linked to 727ce9e and develop is linked alos on 727ce9e .
git checkout develop
Then git lg display :
* 939516a - (main) Team of 2 players (2 hours ago)
* 727ce9e - (HEAD -> develop) First commit (4 hours ago)
Alternative, to avoid the detach HEAD, you could just, but don’t now :
git switch -c develop
To simulate this situation, we want to delete develop branch to recreate, so we have this situation :
* 939516a - (main) Team of 2 players (2 hours ago)
* 727ce9e - (HEAD -> develop) First commit (4 hours ago)
Detach the HEAD with git checkout 727ce9e :
* 939516a - (main) Team of 2 players (2 hours ago)
* 727ce9e - (HEAD, develop) First commit (4 hours ago)
Then delete the develop branch with :
git branch -d develop
Then we can create the new branch with :
git switch -c develop
Now we will update the file to create a new branch, edit equipe1.txt file as :
EQUIPE
##########
Pierre
Then commit this version and display situation ( -am is equivalent as -a -m) :
git commit -am "Nice version"
Then display:
* 8c63cc4 - (HEAD -> develop) Nice version (22 seconds ago)
| * 939516a - (main) Team of 2 players (31 minutes ago)
|/
* 727ce9e - Initial version (53 minutes ago)
Two branches : main to the main software development and develop to try some stuffs
VScode now allows to choose to checkout on a branch easily :
7/ Merge
Suppose we want to simulate some one who works on the main branch adding person to the list :
git checkout main
Then edit the file and save it with a third person as :
Pierre
Gérard
Killian
Then commit this new version with Vscode for example (note the dialog to ask to include -a or always) :
Or from the command line with :
git commit -am "Team of 3"
This is the situation :
* b123fa0 - (HEAD -> main) Team of 3 (3 seconds ago)
* 939516a - Team of 2 players (39 minutes ago)
| * 8c63cc4 - (develop) Nice version (9 minutes ago)
|/
* 727ce9e - Initial version (62 minutes ago) <pierre-jean-dhm>
Then now return on the develop branch with :
git checkout develop
We want to merge the nice version of develop branch into the main branch with :
Or the command
git merge main
It could be possible the fusion is OK because there is no conflict really with this final result :
* 8c63cc4 - (HEAD -> develop) Merge branch 'main' into develop (71 minutes ago)
|\
| * b123fa0- (main) Team of 3 (74 minutes ago)
| * 939516a - Team of 2 players (4 hours ago)
* | 8c63cc4 - Nice version (78 minutes ago)
|/
* 727ce9e - First commit (5 hours ago)
Often, you will have a conflict with this interface :
Ok a bizarre and historical way to display content is sotred into equipe1.txt file, top a part from develop branch and bottom the part from main branch. You can have common part before and later the series of <<<<< and >>>>>>. But swith to « Merge editor with the nice button » :
Ok on the top left the part from main branch call incoming, on the top right, the part from the HEAD (current) develop branch and bellow, the final combinaison of the merge of content. Of course you can edit this final result content as you wish and then press « Complete Merge » to validate the merge.
BUT, is onlyj ust like we create a new content into the equipe1.txt file, we need to commit this new situation with:
git commit -am "Merge branch 'main' into develop"
What is our situation :
* 36bd9a0 - (HEAD -> develop) Merge branch 'main' into develop (81 seconds ago)
|\
| * b123fa0 - (main) Team of 3 (31 minutes ago)
| * 939516a - Team of 2 players (71 minutes ago)
* | 8c63cc4 - Nice version (40 minutes ago)
|/
* 727ce9e - Initial version (2 hours ago)
Next step a special case of merge
8/ Merge fast-forward
We are in a situation of the develop branch is one step forward the main branch. We can also now merge the develop branch into the main branch to simulate the preparation to share the main branch with other paople.
git checkout main
git merge develop
In this specific situation, Git succed to combine the content from develop branch equipe1.txt into main branch equipe1.txt.
To display difference, you can enter use this command (and yes we use ~1 as HEAD~1) :
git difftool -y -x sdiff develop main~1
Side by side :
EQUIPE EQUIPE
########## ##########
Pierre / Pierre
Gérard <
Killian <
In this particular case, we do not have to commit because the merge succed without conflict.
So suppose we want to cancel this situation and just move the main branch label on the previsous commit identified by b123fa0 – Team of 3, we can have two solutions :
- First option just move the branch on a spécific commit with :
git branch -f main b123fa0
- Second option move the HEAD with the main branch and return the HEAD on the develop branch:
git checkout main
git reset --hard b123fa0
git checkout develop
This initial situation at the end will be :
* 36bd9a0 - (HEAD -> develop) Merge branch 'main' into develop (40 minutes ago)
|\
| * b123fa0 - (main) Team of 3 (70 minutes ago)
| * 939516a - Team of 2 players (2 hours ago)
* | 8c63cc4 - Nice version (79 minutes ago)
|/
* 727ce9e - Initial version (2 hours ago)
This a way to cancel movement of the branch, but be aware that the main branch will be syncrhonise with a remote repository call remote origin/main.
Remote
Ok now everything we done is only local. We need to link to Github, so we need information keep at the begining as the git token (symbolise by ghp_XXXXXXXXX later) and the url :
https://github.com/pierre-jean-dhm/hello1.git
We need to create this termnal command with you information :
git remote add origin https://ghp_XXXXXXXXX@github.com/pierre-jean-dhm/hello1.git
In fac this will create a short name « origin » to your hello1.git repository. You can choose something other than origin as github but origin is really commun.
or we can use the Vscode menu insert at first the link https://ghp_XXXXXXXXX@github.com/pierre-jean-dhm/hello1.git then the name of the link origin as usual:
Please, do not accept Vscode to periodicaly fetch content, we do not need it at first.
We forget something, we want to push main branch and we are at present on develop branch. Think about it all the time please!
So option 1 just with this command line :
git push -u origin main
Or option 2, change to main branch then push :
or the command line :
git checkout main
Then git push to the remote repository with branch publish also:
The purpose at this moment is to have always main branch update and link to the remote branch.
You can go online to reresh the page and find everything:
- Top left: the main branch
- Top right: 3 commits from your computer
- Center: our unique equipe1.txt file
You can open the file to see the last content and you can list all the commit to find history of commit or you can open the equipe1.txt file to see history also.
You can see the commit comments and unique number but only the main branch is uploaded.
In local you can see now there is a new remote origin/main branch with git lg command (or the short version git log –oneline –graph –all –decorate) :
* 36bd9a0 - (develop) Merge branch 'main' into develop (23 hours ago)
|\
| * b123fa0 - (HEAD -> main, origin/main) Team of 3 (23 hours ago)
| * 939516a - Team of 2 players (24 hours ago)
* | 8c63cc4 - Nice version (23 hours ago)
|/
* 727ce9e - Initial version (24 hours ago)
Now it is time to simulate a conflict with an external user.
Remote conflict
We will simulate a conflict between the origin/main branch and your local branch, on the main repository file you can click on the equipe1.txt file :
Then on the right, the pen button or the short menu then « Edit online » let you edit the file :
Change the content Equipe as bellow:
TEAM
##########
Pierre
Gérard
Killian
Then you have to « Commit » this new version with the top right button, this will open a dialog box to enter the messsage :
At this point, the online origin/main is updated but NOT your local version. There are two solutions from here BUT before please backup (see below) :
- Download the remote origin/main branch to look what it could happen with : git fetch
- Download the remote origin/main branch to stray away merge to your HEAD: git pull
We can say « git fetch » and « git merge » is equivalent as « git pull ». Git fetch is the light version, you can download from Github but your ane not sure to use it. Git pull is you will download from Github but you use it at present.
This is the situation with git lg before git fetch:
* 36bd9a0 - (develop) Merge branch 'main' into develop
|\
| * b123fa0 - (HEAD -> main, origin/main) Team of 3
| * 939516a - Team of 2 players
* | 8c63cc4 - Nice version
|/
* 727ce9e - Initial version
after git fetch as a command on via menu
And again git lg to display :
* 327e940 - (origin/main) Add Team title
| * 36bd9a0 - (develop) Merge branch 'main' into develop
| |\
| |/
|/|
* | b123fa0 - (HEAD -> main) Team of 3
* | 939516a - Team of 2 players
| * 8c63cc4 - Nice version
|/
* 727ce9e - Initial version
So we have a potentiel conflict display by Vscode betwen the main branch and the remote origin/main branch :
NOTE A optionnal compare with develop : We can also checkout the develop branch to try to merge with the origin/main branch to try to see what inspact it will be on the develop branch. Just try to merge, open the « Resolve into the Merge Editor » then to cancel enter command git merge –abort. Byt the way, how I know the command, just git status to display information. Just think to return on the main branch : git checkout main.
So option 1 : git merge will update directly the equipe1.txt content and the final situation will be main branch is identifical at origin/main branch :
* 327e940 - (HEAD -> main, origin/main) Add Team title
| * 36bd9a0 - (develop) Merge branch 'main' into develop
| |\
| |/
|/|
* | b123fa0 - Team of 3
* | 939516a - Team of 2 players
| * 8c63cc4 - Nice version
|/
* 727ce9e - Initial version
And we also know a futur conflict will be with develop branch, but we will see that later.
Now go back to test option 2, close VScode, rename Hello1 folder into Hello1-Option1, copy the backup Hello1 into Hello1, restart Vscode, menu View Terminal and button on the top left bar « Source control » :
You can also open the equipe1.txt file (Menu File > Open File … ) Then git lg command :
* 36bd9a0 (develop) Merge branch 'main' into develop
|\
| * b123fa0 (HEAD -> main, origin/main) Team of 3
| * 939516a Team of 2 players
* | 8c63cc4 Nice version
|/
* 727ce9e Initial version
Ok now we wand to download the remote origin/main branch to stray away merge to your HEAD. We know online the last version is the best, we just want this version to be update with the main branch so go on.
At this point, because Git find a way to avoid conflict between the online version and the actual versio, juste equipe1.txt will work perfect and merge. We see on the screen, on the right, lines in yellow are copy to the left so everything is fine :
But suppose we merge with develop that for sure will create a conflict try with git merge develop then use the menu to create your combinaison of setting (Use CTRL+Z to cancel o Menu Edit > Undo)
I choose to create this content with « accept incomming » and edit the last line with ######:
EQUIPE
##########
Pierre
Gérard
Killian
########
Then press « Complete Merge » to finalise the conflict from main and develop, then create the new commit 36bd9a0 with this result from git lg output :
* eefe254 - (HEAD -> main) Merge branch 'develop' (4 seconds ago) <pierre-jean-dhm>
|\
| * 36bd9a0 - (develop) Merge branch 'main' into develop (29 hours ago) <pierre-jean-dhm>
| |\
| * | 8c63cc4 - Nice version (30 hours ago) <pierre-jean-dhm>
* | | 327e940 - (origin/main) Add Team title (5 hours ago) <pierre-jean-dhm>
| |/
|/|
* | b123fa0 - Team of 3 (29 hours ago) <pierre-jean-dhm>
* | 939516a - Team of 2 players (30 hours ago) <pierre-jean-dhm>
|/
* 727ce9e - Initial version (30 hours ago) <pierre-jean-dhm>
We need to push to update origin/main as we always say to check main equal to origin/main
Ok now we have this situation with git lg :
* eefe254 - (HEAD -> main, origin/main) Merge branch 'develop'
|\
| * 36bd9a0 - (develop) Merge branch 'main' into develop
| |\
| * | 8c63cc4 - Nice version
* | | 327e940 - Add Team title
| |/
|/|
* | b123fa0 - Team of 3
* | 939516a - Team of 2 players
|/
* 727ce9e - Initial version
At this point, about develop branch, we could create a new develop branch for a new feature.
- Delete develop branch and recreate it later
- Merge develop branch with main branch to start later with this branch
- Move the flag develop from 36bd9a0 to eefe254 and tag the commit with git tag develop-pretty-title
- Rename develop branch as develop-pretty-title branch to keep this feature in mind
I recommand to keep the branch attach so rename a develop branch into an explicit name to keep in mind is the best. We will create later a develop-new-feature branch as needed. We don’t push this kind of branch on GitHub is just a way to work on side features instead have too much change on the main branch.
Simulate an other user
Create a new terminal independant of the first one, press ALT key and click to open a parallel terminal :
Enter the following command to go top folder, create a new folder, go insite this folder and then create a git account :
cd ..
mkdir Hello1-other-user
cd Hello1-other-user
git init
We will create another account just my case swap family name and first name :
git config user.email "jean.pierre@umontpellier.fr"
git config user.name "JEAN Pierre"
Now we will simulate a new challenger on this project who want to clone from the remote GitHub folder the whole project with the same token:
git remote add origin https://ghp_XXXXXX@github.com/pierre-jean-dhm/hello1.git
Then download the whole main branch from origin :
git pull origin main
We are suppose now to image a large contribution from this new user, open the file equipe1.txt in parallel with this combinaison :
Open the menu File > Open files … then move to one up folder, then choose the other sub folder called Hello1-other-user then open equipe1.txt file :
Then you can displays both file, right click on the tab to choose « Split Right » menu
And after close this tab because Split Right duplicate
Now we can display at the left equipe1.txt file from Hello1 and its console and at the right equipe1.txt file from Hello1-other-user and its console :
This exercice suppose to work on this specific situation:
- The right user will create a new developer-complex-feature branch and create one commit on the files, for example add email for the first person
- But the left user will works on the main branch and add two more commits with more peoples on the list
- The right user knows there are update but he needs more time to work on his file but he can wait to receive update
With the right user
git branch developer-complex-feature
git checkout developer-complex-feature
# edit the file adding an email
git commit -am "Update email first person"
With the left user
# edit the file adding one more people
git commit -am "Teams of 4 peoples"
# edit the file adding one more people
git commit -am "Teams of 5 peoples"
git push origin main
With the right user need to receive update
git pull origin main
git checkout main
git merge origin/main
Now we have this situation :
* 629b770 - (HEAD -> main, origin/main) Teams of 5 peoples (4 minutes ago)
| * 19eb774 - (developer-complex-feature) Update email first person (7 minutes ago)
|/
* eefe254 - Merge branch 'develop' (3 days ago)
|\
| * 36bd9a0 - Merge branch 'main' into develop (4 days ago)
| |\
| * | 8c63cc4 - Nice version (4 days ago)
So developer-complex-feature is link to eefe254 commit and it is « too early » we need more time, so we can move the branch (call rebase) from eefe254 to a more recent commit into the timeline, so :
git checkout developer-complex-feature
git rebase main
So the new situation will be :
* d5338af - (HEAD -> developer-complex-feature) Update email first person (5 seconds ago)
* 629b770 - (origin/main, main) Teams of 5 peoples (5 minutes ago)
* eefe254 - Merge branch 'develop' (3 days ago)
|\
| * 36bd9a0 - Merge branch 'main' into develop (4 days ago)
| |\
| * | 8c63cc4 - Nice version (4 days ago)
And right user can work on more updated content from equipe1.txt file and the content is :
EQUIPE
##########
Pierre p.j@mine_ales.com
Gérard
Killian
Simon
Stéphane
########
A very important information : never rebase a online branches like main branch.
You can simulate more commits for the left user and rebase for the right user until right user finish and push modifications on Github main branch.
At the end, change everything on the developer-new-feature branch, save file and commit the change into a new commit :
git commit -am "Update emails"
We can merge from developer-new-feature branch, we need to move on the main branch and merge and push :
git checkout main
git merge developer-new-feature
git push origin main
You can go online to find the Github commit page and display commit from the right user and commit from the left user :
Ok of course, you can now git pull origin main for the left user and go on simulate conflict and development. We can see also with the classic git lg command :
* 7551fa3 - (HEAD -> main, origin/main) Update emails <JEAN Pierre>
* d5338af - Update email first person <JEAN Pierre>
* 629b770 - Teams of 5 peoples <pierre-jean-dhm>
* eefe254 - Merge branch 'develop' <pierre-jean-dhm>
|\
| * 36bd9a0 - (develop) Merge branch 'main' into develop <pierre-jean-dhm>
| |/
|/|
* | b123fa0 - Team of 3 <pierre-jean-dhm>
* | 939516a - Team of 2 players <pierre-jean-dhm>
|/
* 727ce9e - Initial version (4 days ago) <pierre-jean-dhm>
Additionnals operations
Hide files from Git
Put a word document into the folder, you will see it all the time not « added » (not tracked) by Git :
So you can create a .gitignore file with the following content and save it into the same folder where your execute git init (Hello1 in ours case) :
*.docx
*.xlsx
*.pptx
All files with .docx, .pdf, .xlsx, *.pptx will be ignored by Git. Off couse, you will se that you can tracked (git add) the .gitignore file or you can add .gitignore at the end of your .gitignore file.
Many websites provide sample for .gitignore file: https://github.com/github/gitignore
Move files and git status
Suppose you create a new file equipe2.txt into the folder with the folowing content:
EQUIPE
###########
You can add to git the « untracked/unstaged » file with the git add but you forget. Many time if you need to understand which command will be more usuful just enter git status :
On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
equipe2.txt
nothing added to commit but untracked files present (use "git add" to track)
Use git add or the plus button to add the file and enter git status :
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: equipe2.txt
So to rever the git add command, you will see the command :
git restore --staged equipe2.txt
Now move to develop branch, git add equipe2.txt file and commit
git checkout develop
git add equipe2.txt
git commit -m "Add equipe2 file"
Now suppose you want to cancle last commit has it never exists :
git reset --soft HEAD~1
The git status will display the moment after the git add :
On branch develop
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: equipe2.txt
Add authentication to Github easely
You can download the Github client with https://cli.github.com/ and install it on your computer. Then start this command from Windows terminal:
"c:\Program Files\GitHub CLI\gh.exe" auth login
You will be ask for severals questions as (my answers are in bleu):
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
Authenticate Git with your GitHub credentials? No
How would you like to authenticate GitHub CLI? Paste an authentication token
Then you will can paste you generated token but before you must add to it right read:org :
Then you terminal will be link to Github website. You can confirm with :
"c:\Program Files\GitHub CLI\gh.exe" auth status
github.com
✓ Logged in to github.com account pierrejean (keyring)
- Active account: true
- Git operations protocol: https
- Token: ghp_************************************
- Token scopes: 'read:org', 'repo'