Jump to content

Git: Difference between revisions

1,109 bytes added ,  Yesterday at 21:42
no edit summary
mNo edit summary
No edit summary
 
Line 2: Line 2:


If you are looking for a guide on how to host your git repo on Redbrick, click [[Hosting_a_Git_Repo_on_Redbrick|here]]!
If you are looking for a guide on how to host your git repo on Redbrick, click [[Hosting_a_Git_Repo_on_Redbrick|here]]!
For this guide we will be using the Git CLI.


== What is Git? ==
== What is Git? ==
Line 20: Line 22:
* You "stage" the files you've changed
* You "stage" the files you've changed
* You then "commit" these staged files, adding them to the repository.
* You then "commit" these staged files, adding them to the repository.
== Creating Your First Repository ==
Say you have a project that you want to backup with git in ~/my/project. First we need to navigate to the project with the cd command:
    cd ~/my/project
Then we create the repository:
    git init
We can then stage the files. The * here means all of the files in the directory:
    git add *
Finally, we can commit the changes:
    git commit -m "initial commit"
If you have sensitive files you don't want to be added to the repository, such as .env files, you can use a '''.gitignore''' file at the project root.
    cd ~/my/project
    touch .gitignore
Any files or directories specified in the gitignore will not be added to your repository. For example:
    *.env # ignores any files with the extension .env
    hello.* # ignores any files starting with hello.
    /foo # ignores the entire directory foo
You can also specifically allow files or directories inside of ignored directories using an !:
    !/foo/bar # specifically allows the file bar in the foo directory, even though foo is in the gitignore file
9

edits