xxxxxxxxxx
Setting up a new Git Repo
========================
##Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:alexpchin/<reponame>.git
git push -u origin master
##Push an existing repository from the command line
git remote add origin git@github.com:alexpchin/<reponame>.git
git push -u origin master
xxxxxxxxxx
…or create a new repository on the command line
echo "# mehdi-raft" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/MominIqbal-1234/quick-django.git
git push -u origin main
…or push an existing repository from the command line
git remote add origin https://github.com/MominIqbal-1234/quick-django.git
git branch -M main
git push -u origin main
mefiz.com
DRY is stands for “Don’t Repeat Yourself”. In the book of ‘The Pragmatic Programmer’, we can see this definition for DRY:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. This means that, you must try to maintain the behavior of a functionality of the system in a single piece of code, it should not have duplicated code or design item.
Since we are looking these principles for system design, we will follow same concepts with software development. It’s easier to maintain a code or system that is only in one place, because if you need to change something in the code or system, you just need to change in one place.
Besides that, if you have the same code in two or more places, the code can be change during the time, and when this happens it will become bugs in your system. Duplicated code also makes the code more complex and unnecessarily larger.
xxxxxxxxxx
DRY Principle: "Don't Repeat Yourself."
It means avoid code duplication by defining
functions or constants once and reusing them.
This reduces bugs and improves code
maintainability.
Git hub Commands
xxxxxxxxxx
TOP GITHUB COMMANDS
1 - git config –global user.name “[name]” -> sets author name
git config –global user.email “[email address]” -> sets author email id
2 - git init [repository name] -> start new repository
3 - git clone [url] -> obtain a repository from an existing URL.
4 - git add [file] -> adds a file to the staging area.
5 - git commit -m “[ Type in the commit message]” -> records or snapshots the file permanently in the version history.
git commit -a -> commits any files you’ve changed since then.&commits any files you’ve added
6 - git diff -> shows the file differences which are not yet staged.
git diff –staged -> differences between the files in the staging area and the latest version present.
git diff [first branch] [second branch] -> differences between the two branches mentioned.
7 - git reset [file] -> unstages the file, but it preserves the file contents.
git reset [commit] -> undoes all the commits after the specified commit and preserves the changes locally.
git reset –hard [commit] -> discards all history and goes back to the specified commit.
8 - git status -> command lists all the files that have to be committed.
9 - git rm [file] -> deletes the file from your working directory and stages the deletion.
10 - git log -> used to list the version history for the current branch.
git log –follow[file] -> lists version history for a file, including the renaming of files also.
11 - git show [commit] -> shows the metadata and content changes of the specified commit.
12 - git tag [commitID] -> used to give tags to the specified commit.
13 - git branch ->lists all the local branches in the current repository.
14 - git branch [branch name] -> creates a new branch.
git branch -d [branch name] -> deletes the feature branch.
15 - git checkout [branch name] -> used to switch from one branch to another
git checkout -b [branch name] -> creates a new branch and also switches to it.
16 - git merge [branch name] -> merges the specified branch’s history into the current branch.
17 - git remote add [variable name] [Remote Server Link] -> used to connect your local repository to the remote server.
18 - git push [variable name] master -> sends the committed changes of master branch to your remote repository.
git push [variable name] [branch] -> sends the branch commits to your remote repository.
git push –all [variable name] -> pushes all branches to your remote repository.
git push [variable name] :[branch name] -> deletes a branch on your remote repository.
19 - git pull [Repository Link] -> fetches and merges changes on the remote server to your working directory.
20 - git stash save -> stores all the modified tracked files.
21 - git stash pop -> restores the most recently stashed files.
git stash list -> lists all stashed changesets.
git stash drop -> discards the most recently stashed changeset.