Git on your Local machine:
Check if you have Git on your local machine: git --version
If not, install it on linux,mac or win.
- Set your username: git config --global user.name "FIRST_NAME LAST_NAME"
- Set your email address: git config --global user.email "MY_NAME@example.com"
- Which command allows you to transform a classic folder into a local git project?
git init
- Which command allows you to move a file to the staging directory?
git add
- Which command allows you to create a commit?
git commit
let's talk SSH
github-doc
The instructions you have followed in this tutorial have created 2 files in your /home//.ssh/ folder :
- the first one (id_ed25519) : this is your private key, you must NEVER publish it or share it with anyone, it must exist on your computer only;
- the second one (id_ed25519.pub) : this is your public key, that you will share on GitHub following the instructions in the next step of this quest.
add your public key in your GitHub settings
You can save multiple SSH keys on you GitHub account. For example, if you want to work with Git and GitHub from different computers, you will have to repeat those steps one by one on each of your computers, so that they each have their own SSH key linked to your GitHub account.
- set up a remote repository by using
git remote add origin <REMOTE_URL>
orgit clone <REMOTE_URL>
the one you need starts with git@github.com: .When using this address (for example by running git clone git@github.com:/ in your local Git repository), your repository will be configured to use SSH authentication with the keys you created and configured in GitHub earlier. Thanks to SSH athentication, you don't have to enter your GitHub username and password, the authentication process is automatic.
Finding the git@github.com: url of a remote repository is quite simple : just go to the repository in question on GitHub, and click on the green "Code" button. Select "SSH", copy the address it displays, and that's it!
send your sources to a remote repository
git remote add origin <REMOTE_URL>
confirm by git remote -v
Push: To upload information from the local repo to the remote repo.
git push origin main
Retrieve changes
git pull origin main
which is actually this two:
git fetch origin
git merge origin/main
Copy remote repository to your local machine
git clone <REMOTE_URL>
follow the flow - branching
create a new branch git checkout -b <branchName>
switch to a exciting branch git checkout <branchName>
to check which branch you are on git branch -a
which are exciting git branch
delete a branch locally (jump off +) git branch --delete <branchName>
merging code between branches
when merging, we need to be on the branch that we want to merge to. Basically, we will be telling git, “See that new thing? It’s ok to bring it over here now.”
git merge –no-ff <branchName>
— the additional –no-ff
tells git we want to retain all of the commit messages prior to the merge.
To delete a merged branch: git branch -d <branchName>
merge conflict
If we do a git status it should still show our conflict. Since we want to keep the one from my new version, simply delete the lines that Git plopped in there and the old version. Then just add and commit the file as normal, and your merge is resolved!
stash
add your changes to the index using git add .
stash your changes away: git stash
bring your changes back: git stash apply
if you got multiple layers of stashes: git stash list
apply the second stash git stash apply stash@{1}
deletes that stash for good: git stash drop <id>
delete all of the stored stashes: git stash clear
reverting files
git tagging
$ git tag
to list existing tags
lightweight tag git tag TAG_NAME
annotated tag git tag -a v1.0 -m "Version 1.0"
git push origin --tags
Top comments (0)