Best practice to follow on git and github
Some basics: linux
Note: <> just used to differentiate the file for understanding:
ls -list the file
mkdir <folder name> - creach the file name
touch <file name> - create the file
code . - take to vs code
vi <filename >- open the vim editor - Don’t dive deep into vim editor
There are two mode Edit mode and command mode
You can press Esc to enter cmd mode to give command like insert delete update and so on
i - for insert a text in a file O, o move the cursor above and below
:wq - write and save the file
These are the basic about vim editor but don’t spend too much time on this use other editor for faster progress and so on
We can directly open the file and made the changes
Vim is fun to learn
cat <file name > - show what are there in that file
rm -rf <file/folder name> -remove the the file or folder from the current directory
cd - change the directory(where we are working and our file path)
cd .. go back the previous folder in a directory
Git configuration
git config --global user.name “[firstname lastname]”
git config --global user.email “[valid-email]”
git config --list(Will give your configuration list)
Working with git and github
git init- initialise the git on the folder.
git status to know which branch your are working
Always create a new branch and start working
git branch <branch name> - create a branch
git checkout <branch name> -switch to branch
git add . for adding all file to staging
git add <file name> for single file
git commit -m “Your msg like what changes you have made”
git log - show how much commit you did
git restore –staged <file name> - if you add the file by mistake it go back and remove the add
Check git log -it show the commit
git log give the list of commit and id
git reset <id> - remove the commit before the commit id
git stash - changes you make go back to stage
git stash pop - changes come back again
git stash clear - back in the stage is clear
Ideal scenario:
Create a repository in your account or if you are working in an open source repo fork it and have that repo in your github account that how you can change or contribute to the folder.
After that clone the repo
And create a branch and start working the feature(if it's another person repo create branch , if it's yours main start working on the main.you can also create branch and start working on your repo for learning purpose and keep track what feature you are working on.
Whenever you are working give the (git pull) on main to get the latest version of the repo
git fetch –fetch –all –prune
git reset –hard upstream
git push origin main/master
or
git pull upstream main
git push origin main/master
or
select fetch upstream in the github ui to update with main
Make sure you are in the main branch
git pull - to pull the new changes in main and give
git merge <branch name > after that create a pull request once your code is reviewed reviewer will merge.
If it is the same issue, many people are working together, conflict may occur, resolve the conflict by discussion and so on and search the internet on how to solve it.
If you are working on your own repo direct pull from old and push from new changes it will be straight forward.
Where i wasted time maybe you can waste:
Don’t learn so much about vim it just editor you can use vs code or notepad
Whenever you push your changes
Github username and password not going to work so you have generate a token
Path - github - settings - developer setting - personal access token - new token - generate token – give access to the repository - token will generate save it wherever you want
Whenever it asks for a user name, gives the user name and password, pastes the code it is not visible and press enter will push changes local to the repository.
Comments
Post a Comment